MainActivity.java 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  1. package ru.ktk45.www.feature;
  2. import android.app.DatePickerDialog;
  3. import android.graphics.Typeface;
  4. import android.os.Bundle;
  5. import android.os.StrictMode;
  6. import android.support.annotation.Nullable;
  7. import android.support.design.widget.FloatingActionButton;
  8. import android.support.design.widget.Snackbar;
  9. import android.support.v4.content.res.ResourcesCompat;
  10. import android.text.InputType;
  11. import android.util.Log;
  12. import android.util.TypedValue;
  13. import android.view.Gravity;
  14. import android.view.View;
  15. import android.support.design.widget.NavigationView;
  16. import android.support.v4.view.GravityCompat;
  17. import android.support.v4.widget.DrawerLayout;
  18. import android.support.v7.app.ActionBarDrawerToggle;
  19. import android.support.v7.app.AppCompatActivity;
  20. import android.support.v7.widget.Toolbar;
  21. import android.view.Menu;
  22. import android.view.MenuItem;
  23. import android.view.ViewGroup;
  24. import android.webkit.WebSettings;
  25. import android.webkit.WebView;
  26. import android.widget.AdapterView;
  27. import android.widget.ArrayAdapter;
  28. import android.widget.DatePicker;
  29. import android.widget.EditText;
  30. import android.widget.FrameLayout;
  31. import android.widget.LinearLayout;
  32. import android.widget.Spinner;
  33. import android.widget.TableRow;
  34. import android.widget.TextView;
  35. import android.widget.Toast;
  36. import org.json.JSONArray;
  37. import org.json.JSONException;
  38. import org.json.JSONObject;
  39. import org.w3c.dom.Text;
  40. import java.io.IOException;
  41. import java.io.UnsupportedEncodingException;
  42. import java.text.SimpleDateFormat;
  43. import java.util.Calendar;
  44. import java.util.Date;
  45. import java.util.Locale;
  46. public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
  47. // Динамический список подразделений
  48. private ArrayAdapter<String> _BranchCaption;
  49. private ArrayAdapter<String> _BranchHash;
  50. private int _BranchSelectID;
  51. private int _GroupSelectID;
  52. private int _ScheduleLayoutID;
  53. // Динамический список групп для расписания (для установки в список Spinner'а)
  54. private ArrayAdapter<Integer> _Group;
  55. // Объект с группами подразделений
  56. private JSONArray _GroupList;
  57. private final Calendar _Calendar = Calendar.getInstance();
  58. private final Calendar _CalendarMon = Calendar.getInstance();
  59. private final Calendar _CalendarSat = Calendar.getInstance();
  60. private final SimpleDateFormat _DateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
  61. private final SimpleDateFormat _DateQueryFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
  62. private EditText _DateSetup;
  63. // Для сохраниения даты подготовленной для отправки запроса расписания
  64. private int _DateIs = 0;
  65. private String[] _DateIsString = new String[2];
  66. // LinearLayout основного окна
  67. private LinearLayout _ContentPage;
  68. @Override
  69. protected void onCreate(Bundle savedInstanceState) {
  70. super.onCreate(savedInstanceState);
  71. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
  72. StrictMode.setThreadPolicy(policy);
  73. setContentView(R.layout.activity_main);
  74. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  75. setSupportActionBar(toolbar);
  76. FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  77. fab.setOnClickListener(new View.OnClickListener() {
  78. @Override
  79. public void onClick(View view) {
  80. Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
  81. .setAction("Action", null).show();
  82. }
  83. });
  84. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  85. ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
  86. this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  87. drawer.addDrawerListener(toggle);
  88. toggle.syncState();
  89. NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  90. navigationView.setNavigationItemSelectedListener(this);
  91. _ContentPage = (LinearLayout) findViewById(R.id.content_layout);
  92. setWeekDateRange();
  93. loadScheduleFilter();
  94. createGuestSchedule();
  95. loadSchedule();
  96. }
  97. @Override
  98. public void onBackPressed() {
  99. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  100. if (drawer.isDrawerOpen(GravityCompat.START)) {
  101. drawer.closeDrawer(GravityCompat.START);
  102. } else {
  103. super.onBackPressed();
  104. }
  105. }
  106. @Override
  107. public boolean onCreateOptionsMenu(Menu menu) {
  108. // Inflate the menu; this adds items to the action bar if it is present.
  109. getMenuInflater().inflate(R.menu.main, menu);
  110. return true;
  111. }
  112. @Override
  113. public boolean onOptionsItemSelected(MenuItem item) {
  114. // Handle action bar item clicks here. The action bar will
  115. // automatically handle clicks on the Home/Up button, so long
  116. // as you specify a parent activity in AndroidManifest.xml.
  117. int id = item.getItemId();
  118. //noinspection SimplifiableIfStatement
  119. if (id == R.id.action_settings) {
  120. return true;
  121. }
  122. return super.onOptionsItemSelected(item);
  123. }
  124. @SuppressWarnings("StatementWithEmptyBody")
  125. @Override
  126. public boolean onNavigationItemSelected(MenuItem item) {
  127. // Handle navigation view item clicks here.
  128. int id = item.getItemId();
  129. if (id == R.id.nav_news) {
  130. loadNews();
  131. } else if (id == R.id.nav_schedule) {
  132. setWeekDateRange();
  133. loadScheduleFilter();
  134. createGuestSchedule();
  135. loadSchedule();
  136. } else if (id == R.id.nav_schedule_call) {
  137. } else if (id == R.id.nav_manage) {
  138. } else if (id == R.id.nav_send) {
  139. }
  140. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  141. drawer.closeDrawer(GravityCompat.START);
  142. return true;
  143. }
  144. public void loadNews() {
  145. try {
  146. Link h = new Link();
  147. h.SetParameter("Limit", "20");
  148. h.SetParameter("Page", "0");
  149. JSONObject obj = h.POST("/news");
  150. if (obj == null) {
  151. Toast toast = Toast.makeText(getApplicationContext(), "Ошибка получения данных", Toast.LENGTH_LONG);
  152. toast.show();
  153. return;
  154. }
  155. if (obj.getString("Error").equals("null")) {
  156. _ContentPage.removeAllViewsInLayout();
  157. LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  158. LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  159. // layoutParams.gravity = Gravity.FILL_HORIZONTAL;
  160. layoutParams.bottomMargin = 15;
  161. layoutParams.leftMargin = 0;
  162. layoutParams.rightMargin = 0;
  163. layoutParams.topMargin = 0;
  164. //
  165. // layoutParams2.bottomMargin = 0;
  166. // layoutParams2.leftMargin = 0;
  167. // layoutParams2.rightMargin = 0;
  168. // layoutParams2.topMargin = 0;
  169. JSONArray _news = obj.getJSONArray("News");
  170. Typeface face = ResourcesCompat.getFont(this, R.font.play_regular);
  171. for (int i = 0; i < _news.length(); i++) {
  172. JSONObject _n = _news.getJSONObject(i);
  173. LinearLayout field = new LinearLayout(this);
  174. field.setOrientation(LinearLayout.VERTICAL);
  175. field.setLayoutParams(layoutParams);
  176. field.setBackgroundColor(getResources().getColor(R.color.colorWhite));
  177. field.setPadding(10, 10, 10, 10);
  178. // field.setMinimumHeight(100);
  179. TextView _date = new TextView(this);
  180. _date.setText(_n.getString("Published"));
  181. _date.setTextColor(getResources().getColor(R.color.colorGray));
  182. _date.setTypeface(face);
  183. TextView _caption = new TextView(this);
  184. _caption.setLayoutParams(layoutParams2);
  185. _caption.setText(_n.getString("Caption") );
  186. _caption.setTextColor(getResources().getColor(R.color.colorPrimaryDark));
  187. _caption.setTypeface(face);
  188. _caption.setTextSize(18);
  189. newsClick(field, _n.getString("Link"));
  190. field.addView(_date);
  191. field.addView(_caption);
  192. _ContentPage.addView(field);
  193. }
  194. }
  195. } catch (JSONException e) {
  196. Toast toast = Toast.makeText(getApplicationContext(),e.getMessage(), Toast.LENGTH_LONG);
  197. toast.show();
  198. }
  199. }
  200. private void newsClick(final LinearLayout fl, final String link) {
  201. fl.setOnClickListener(new View.OnClickListener() {
  202. @Override
  203. public void onClick(View v) {
  204. Link h = new Link();
  205. try {
  206. JSONObject obj = h.POST("/mtl/"+link);
  207. if (obj == null) {
  208. Toast toast = Toast.makeText(getApplicationContext(), "Ошибка получения данных", Toast.LENGTH_LONG);
  209. toast.show();
  210. return;
  211. }
  212. Log.i("INFO", obj.toString());
  213. JSONObject _news = obj.getJSONObject("mtl");
  214. _ContentPage.removeAllViewsInLayout();
  215. WebView webView = new WebView(MainActivity.this);
  216. webView.loadDataWithBaseURL("http://ktk-45.ru/", getNewsHTML(_news.getString("Caption"), _news.getString("Content")), "text/html", "UTF-8", null);
  217. _ContentPage.addView(webView);
  218. } catch (JSONException e) {
  219. Toast toast = Toast.makeText(getApplicationContext(),e.getMessage(), Toast.LENGTH_LONG);
  220. toast.show();
  221. }
  222. }
  223. });
  224. }
  225. private String getNewsHTML(String caption, String content) {
  226. return cssStyle1 + caption + cssStyle2 + content + cssStyle3;
  227. }
  228. private static final String cssStyle1 = "<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><style type=\"text/css\">@font-face{font-family:'play';src:url(\"/assets/fonts/google/Play/Play-Regular.ttf\")} body{font-family:'play' !important;} p{text-indent:2.5em;text-align:justify;margin: 10px 0 10px 0;} .the-news-signature{font-style: italic;text-align: right;padding-top: 16px;} h1{text-align:center;font-size:18px;} hr{margin:20px 0;} a{pointer-events: none;} img{width:100%;} .text-center{text-align:center;} .text-right{text-align:right;}</style></head><body><h1>";
  229. private static final String cssStyle2 = "</h1>";
  230. private static final String cssStyle3 = "</body></html>";
  231. //
  232. // РАСПИСАНИЕ
  233. //
  234. public void loadSchedule() {
  235. }
  236. // Загрузка данных о подразделениях и группах
  237. private void loadScheduleFilter() {
  238. try {
  239. Link h = new Link();
  240. JSONObject obj = h.POST("/select/schedule-filter");
  241. if (obj == null) {
  242. Toast toast = Toast.makeText(getApplicationContext(), "Ошибка получения данных", Toast.LENGTH_LONG);
  243. toast.show();
  244. return;
  245. }
  246. if (obj.getString("Error").equals("null")) {
  247. if (_BranchCaption == null) {
  248. _BranchCaption = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
  249. }
  250. _BranchCaption.clear();
  251. _BranchCaption.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  252. if (_BranchHash == null) {
  253. _BranchHash = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
  254. }
  255. _BranchHash.clear();
  256. if (_Group == null) {
  257. _Group = new ArrayAdapter<Integer>(this, android.R.layout.simple_spinner_item);
  258. }
  259. _Group.clear();
  260. _Group.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  261. if (obj.isNull("Branch")) {
  262. Toast toast = Toast.makeText(getApplicationContext(),"Не удалось получить список подразделений!", Toast.LENGTH_LONG);
  263. toast.show();
  264. return;
  265. }
  266. JSONArray _list = obj.getJSONArray("Branch");
  267. for (int i = 0; i < _list.length(); i++) {
  268. _BranchCaption.add(_list.getJSONObject(i).getString("Caption"));
  269. _BranchHash.add(_list.getJSONObject(i).getString("Hash"));
  270. }
  271. if (obj.isNull("Data")) {
  272. Toast toast = Toast.makeText(getApplicationContext(),"Не удалось получить список групп!", Toast.LENGTH_LONG);
  273. toast.show();
  274. return;
  275. }
  276. _GroupList = obj.getJSONArray("Data");
  277. for (int i = 0; i < _GroupList.length(); i++) {
  278. JSONObject _groupObj = _GroupList.getJSONObject(i);
  279. if (_groupObj.getString("Branch").equals(_BranchHash.getItem(0))) {
  280. JSONArray _groups = _groupObj.getJSONArray("Groups");
  281. for (int j = 0; j < _groups.length(); j++) {
  282. _Group.add(_groups.getInt(j));
  283. }
  284. }
  285. }
  286. }
  287. } catch (JSONException e) {
  288. Toast toast = Toast.makeText(getApplicationContext(),e.getMessage(), Toast.LENGTH_LONG);
  289. toast.show();
  290. }
  291. }
  292. // Загрузка списка групп выбранного подразделения
  293. private void loadGroupList() {
  294. try {
  295. Link h = new Link();
  296. Spinner spinner = (Spinner) findViewById(_BranchSelectID);
  297. int id = (int)spinner.getSelectedItemId();
  298. h.SetParameter("Branch", _BranchHash.getItem(id));
  299. JSONObject obj = h.POST("/select/schedule-call");
  300. if (obj == null) {
  301. Toast toast = Toast.makeText(getApplicationContext(), "Ошибка получения данных", Toast.LENGTH_LONG);
  302. toast.show();
  303. return;
  304. }
  305. if (obj.getString("Error").equals("null")) {
  306. if (_Group == null) {
  307. _Group = new ArrayAdapter<Integer>(this, android.R.layout.simple_spinner_item);
  308. }
  309. _Group.clear();
  310. _Group.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  311. Log.i("INFO", obj.toString());
  312. // if (obj.isNull("Branch")) {
  313. // Toast toast = Toast.makeText(getApplicationContext(),"Не удалось получить список подразделений!", Toast.LENGTH_LONG);
  314. // toast.show();
  315. // return;
  316. // }
  317. // JSONArray _list = obj.getJSONArray("Branch");
  318. // for (int i = 0; i < _list.length(); i++) {
  319. // _Group.add(_list.getJSONObject(i).getString("Caption"));
  320. // }
  321. }
  322. } catch (JSONException e) {
  323. e.printStackTrace();
  324. }
  325. }
  326. public void createGuestSchedule() {
  327. if (_BranchCaption == null) {
  328. // Сообразить сообщение об ошибке
  329. Toast toast = Toast.makeText(getApplicationContext(),"Список подразделений не был получен!", Toast.LENGTH_LONG);
  330. toast.show();
  331. return;
  332. }
  333. if (_Group == null) {
  334. Toast toast = Toast.makeText(getApplicationContext(),"Список групп не был получен!", Toast.LENGTH_LONG);
  335. toast.show();
  336. return;
  337. }
  338. // Для начала нужно сформировать основную форму с фильтрами
  339. final Typeface face = ResourcesCompat.getFont(this, R.font.play_bold);
  340. LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  341. layoutParams.bottomMargin = 20;
  342. layoutParams.leftMargin = 0;
  343. layoutParams.rightMargin = 0;
  344. layoutParams.topMargin = 0;
  345. _ContentPage.removeAllViewsInLayout();
  346. TextView textViewBranchCaption = new TextView(this);
  347. textViewBranchCaption.setText(R.string.branch_label);
  348. textViewBranchCaption.setTypeface(face);
  349. _ContentPage.addView(textViewBranchCaption);
  350. Spinner selectBranch = new Spinner(this);
  351. _BranchSelectID = View.generateViewId();
  352. selectBranch.setId(_BranchSelectID);
  353. selectBranch.setAdapter(_BranchCaption);
  354. selectBranch.setLayoutParams(layoutParams);
  355. // Событие выбора подразделения
  356. selectBranch.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  357. @Override
  358. public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
  359. _Group.clear();
  360. try {
  361. for (int i = 0; i < _GroupList.length(); i++) {
  362. JSONObject _groupObj = _GroupList.getJSONObject(i);
  363. if (_groupObj.getString("Branch").equals(_BranchHash.getItem(position))) {
  364. JSONArray _groups = _groupObj.getJSONArray("Groups");
  365. for (int j = 0; j < _groups.length(); j++) {
  366. _Group.add(_groups.getInt(j));
  367. }
  368. }
  369. }
  370. Spinner spinner = (Spinner) findViewById(_GroupSelectID);
  371. spinner.setAdapter(_Group);
  372. } catch (JSONException e) {
  373. Toast toast = Toast.makeText(getApplicationContext(),e.getMessage(), Toast.LENGTH_LONG);
  374. toast.show();
  375. }
  376. }
  377. @Override
  378. public void onNothingSelected(AdapterView<?> parent) {
  379. }
  380. });
  381. _ContentPage.addView(selectBranch);
  382. TextView textViewGroupCaption = new TextView(this);
  383. textViewGroupCaption.setText(R.string.group_label);
  384. textViewGroupCaption.setTypeface(face);
  385. _ContentPage.addView(textViewGroupCaption);
  386. Spinner selectGroup = new Spinner(this);
  387. _GroupSelectID = View.generateViewId();
  388. selectGroup.setId(_GroupSelectID);
  389. selectGroup.setLayoutParams(layoutParams);
  390. selectGroup.setAdapter(_Group);
  391. selectGroup.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  392. @Override
  393. public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
  394. int selectedGroup = 0;
  395. try {
  396. selectedGroup = _Group.getItem(position);
  397. } catch (NullPointerException e) {
  398. Toast toast = Toast.makeText(getApplicationContext(),e.getMessage(), Toast.LENGTH_LONG);
  399. toast.show();
  400. }
  401. try {
  402. Spinner spinner = (Spinner) findViewById(_BranchSelectID);
  403. Date date = new Date();
  404. Link h = new Link();
  405. h.SetParameter("Branch", _BranchHash.getItem((int)spinner.getSelectedItemId()));
  406. h.SetParameter("Group", ""+selectedGroup);
  407. if (_DateIsString[0] != null) {
  408. h.SetParameter("FirstDate", _DateIsString[0]);
  409. } else {
  410. setWeekDateRange();
  411. h.SetParameter("FirstDate", _DateIsString[0]);
  412. }
  413. if (_DateIsString[1] != null) {
  414. h.SetParameter("LastDate", _DateIsString[1]);
  415. } else {
  416. setWeekDateRange();
  417. h.SetParameter("LastDate", _DateIsString[1]);
  418. }
  419. JSONObject obj = h.POST("/select/schedule-group");
  420. if (obj == null) {
  421. Toast toast = Toast.makeText(getApplicationContext(), "Ошибка получения данных", Toast.LENGTH_LONG);
  422. toast.show();
  423. return;
  424. }
  425. if (!obj.getString("Error").equals("null")) {
  426. Toast toast = Toast.makeText(getApplicationContext(), obj.getString("Error"), Toast.LENGTH_LONG);
  427. toast.show();
  428. return;
  429. }
  430. if (obj.isNull("Data")) {
  431. Toast toast = Toast.makeText(getApplicationContext(), "Данные расписания выбранной группы/даты отсутствуют в базе", Toast.LENGTH_LONG);
  432. toast.show();
  433. return;
  434. }
  435. JSONArray _sch = obj.getJSONArray("Data");
  436. prevDate = "";
  437. LinearLayout schLayout = (LinearLayout)findViewById(_ScheduleLayoutID);
  438. if (schLayout == null) {
  439. Toast toast = Toast.makeText(getApplicationContext(), "Не найден слой для создания расписания", Toast.LENGTH_LONG);
  440. toast.show();
  441. return;
  442. }
  443. schLayout.removeAllViewsInLayout();
  444. for (int i = 0; i < _sch.length(); i++) {
  445. JSONObject _currentPair = _sch.getJSONObject(i);
  446. String _currentDay = _currentPair.getString("Date");
  447. if (!prevDate.equals(_currentDay)) {
  448. schLayout.addView(createDateRow(_currentDay));
  449. prevDate = _currentDay;
  450. }
  451. String _subgroup = _currentPair.getString("Subgroup");
  452. switch (_subgroup) {
  453. case "left":
  454. if (i+1 < _sch.length()) {
  455. JSONObject _next = _sch.getJSONObject(i+1);
  456. if (_currentPair.getString("Pair").equals(_next.getString("Pair")) &&
  457. _next.getString("Subgroup").equals("right")) {
  458. schLayout.addView(createBoth(_currentPair, _next));
  459. i++;
  460. } else {
  461. schLayout.addView(createLeft(_currentPair));
  462. }
  463. }
  464. break;
  465. case "middle":
  466. schLayout.addView(createMiddle(_currentPair));
  467. break;
  468. case "right":
  469. schLayout.addView(createRight(_currentPair));
  470. break;
  471. default: continue;
  472. }
  473. // schLayout.addView(pushSchedulePair(_sch.getJSONObject(i)));
  474. }
  475. } catch (JSONException e) {
  476. Toast toast = Toast.makeText(getApplicationContext(),e.getMessage(), Toast.LENGTH_LONG);
  477. toast.show();
  478. }
  479. }
  480. @Override
  481. public void onNothingSelected(AdapterView<?> parent) {
  482. }
  483. });
  484. _ContentPage.addView(selectGroup);
  485. final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
  486. @Override
  487. public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
  488. _Calendar.set(Calendar.YEAR, year);
  489. _Calendar.set(Calendar.MONTH, month);
  490. _Calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
  491. if (_DateSetup == null) {
  492. Toast toast = Toast.makeText(getApplicationContext(),"Нет элемента для установки даты!", Toast.LENGTH_LONG);
  493. toast.show();
  494. return;
  495. }
  496. _DateSetup.setText(_DateFormat.format(_Calendar.getTime()));
  497. _DateIsString[_DateIs] = _DateQueryFormat.format(_Calendar.getTime());
  498. }
  499. };
  500. LinearLayout.LayoutParams layoutParamsDate = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  501. layoutParamsDate.weight = 0.5f;
  502. LinearLayout _llDate = new LinearLayout(this);
  503. _llDate.setOrientation(LinearLayout.VERTICAL);
  504. LinearLayout _llDateCaption = new LinearLayout(this);
  505. _llDateCaption.setOrientation(LinearLayout.HORIZONTAL);
  506. LinearLayout _llDateDate = new LinearLayout(this);
  507. _llDateDate.setOrientation(LinearLayout.HORIZONTAL);
  508. TextView _tvCaption1 = new TextView(this);
  509. TextView _tvCaption2 = new TextView(this);
  510. _tvCaption1.setTypeface(face);
  511. _tvCaption2.setTypeface(face);
  512. _tvCaption1.setText("Дата с:");
  513. _tvCaption2.setText("по:");
  514. _tvCaption1.setLayoutParams(layoutParamsDate);
  515. _tvCaption2.setLayoutParams(layoutParamsDate);
  516. EditText _etDate1 = new EditText(this);
  517. _etDate1.setInputType(InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_DATE);
  518. _etDate1.setLayoutParams(layoutParamsDate);
  519. _etDate1.setTypeface(face);
  520. _etDate1.setFocusable(false);
  521. _etDate1.setOnClickListener(new View.OnClickListener() {
  522. @Override
  523. public void onClick(View v) {
  524. _DateSetup = (EditText)v;
  525. _DateIs = 0;
  526. new DatePickerDialog(MainActivity.this, date,
  527. _Calendar.get(Calendar.YEAR),
  528. _Calendar.get(Calendar.MONTH),
  529. _Calendar.get(Calendar.DAY_OF_MONTH)).show();
  530. }
  531. });
  532. _etDate1.setText(_DateFormat.format(_CalendarMon.getTime()));
  533. EditText _etDate2 = new EditText(this);
  534. _etDate2.setInputType(InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_DATE);
  535. _etDate2.setLayoutParams(layoutParamsDate);
  536. _etDate2.setTypeface(face);
  537. _etDate2.setFocusable(false);
  538. _etDate2.setOnClickListener(new View.OnClickListener() {
  539. @Override
  540. public void onClick(View v) {
  541. _DateSetup = (EditText)v;
  542. _DateIs = 1;
  543. new DatePickerDialog(MainActivity.this, date,
  544. _Calendar.get(Calendar.YEAR),
  545. _Calendar.get(Calendar.MONTH),
  546. _Calendar.get(Calendar.DAY_OF_MONTH)).show();
  547. }
  548. });
  549. _etDate2.setText(_DateFormat.format(_CalendarSat.getTime()));
  550. _llDateCaption.addView(_tvCaption1);
  551. _llDateCaption.addView(_tvCaption2);
  552. _llDateDate.addView(_etDate1);
  553. _llDateDate.addView(_etDate2);
  554. _llDate.addView(_llDateCaption);
  555. _llDate.addView(_llDateDate);
  556. _ContentPage.addView(_llDate);
  557. LinearLayout.LayoutParams layoutParamsSch = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  558. LinearLayout _llSch = new LinearLayout(this);
  559. _llSch.setOrientation(LinearLayout.VERTICAL);
  560. _llSch.setLayoutParams(layoutParamsSch);
  561. _ScheduleLayoutID = View.generateViewId();
  562. _llSch.setId(_ScheduleLayoutID);
  563. _ContentPage.addView(_llSch);
  564. }
  565. // Установить в элементы Date1 & Date2 диапозон текущей недели
  566. private void setWeekDateRange() {
  567. /*
  568. * 1 Воскресенье 0
  569. * 2 Понедельник 1
  570. * 3 Вторник 2
  571. * 4 Среда 3
  572. * 5 Четверг 4
  573. * 6 Пятница 5
  574. * 7 Суббота 6
  575. *
  576. * */
  577. int IDayToFirstWeedDay[] = {
  578. 1,
  579. 0,
  580. -1,
  581. -2,
  582. -3,
  583. -4,
  584. 0,
  585. };
  586. int IDayToLastWeedDay[] = {
  587. 6,
  588. 5,
  589. 4,
  590. 3,
  591. 2,
  592. 1,
  593. 7,
  594. };
  595. int _day = _Calendar.get(Calendar.DAY_OF_WEEK) - 1;
  596. _CalendarMon.setTimeInMillis((new Date()).getTime() + (86400000 * IDayToFirstWeedDay[_day]));
  597. int _date = _CalendarMon.get(Calendar.DAY_OF_MONTH);
  598. int _month = _CalendarMon.get(Calendar.MONTH) + 1;
  599. int _year = _CalendarMon.get(Calendar.YEAR);
  600. _DateIsString[0] = "" + _year + "-" + _month + "-" + (_date > 9 ? _date : "0" + _date);
  601. _CalendarSat.setTimeInMillis((new Date()).getTime() + (86400000 * IDayToLastWeedDay[_day]));
  602. _date = _CalendarSat.get(Calendar.DAY_OF_MONTH);
  603. _month = _CalendarSat.get(Calendar.MONTH) + 1;
  604. _year = _CalendarSat.get(Calendar.YEAR);
  605. _DateIsString[1] = "" + _year + "-" + _month + "-" + (_date > 9 ? _date : "0" + _date);
  606. }
  607. private String _DayName[] = {
  608. "Воскресенье", "Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота",
  609. };
  610. private String _MonthName[] = {
  611. " января ", " февраля ", " марта ", " апреля ", " июня ", " июля ", " августа ", " сентября ", " октября ", " ноября ", " декабря ",
  612. };
  613. private String prevDate = "";
  614. private LinearLayout createDateRow(String dateStr) {
  615. LinearLayout _ll_day = new LinearLayout(this);
  616. _ll_day.setOrientation(LinearLayout.VERTICAL);
  617. TextView _tv_day = new TextView(this);
  618. final Typeface faceReg = ResourcesCompat.getFont(this, R.font.play_regular);
  619. TableRow.LayoutParams _lp_day = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
  620. _lp_day.weight = 1;
  621. _lp_day.topMargin = 20;
  622. String _currentDay = "";
  623. String __date[] = dateStr.split("-");
  624. try {
  625. _currentDay = __date[2].split("T")[0] + _MonthName[Integer.parseInt(__date[1]) - 1] + __date[0];
  626. } catch (NumberFormatException e) {
  627. _currentDay = __date[2].split("T")[0] + "-" + __date[1] + "-" + __date[0];
  628. }
  629. _tv_day.setText(_currentDay);
  630. _tv_day.setTypeface(faceReg);
  631. _tv_day.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
  632. _tv_day.setLayoutParams(_lp_day);
  633. _tv_day.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
  634. _tv_day.setBackgroundColor(getResources().getColor(R.color.colorSchHead));
  635. _tv_day.setTextColor(getResources().getColor(R.color.colorWhite));
  636. LinearLayout.LayoutParams _llpd = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  637. _llpd.weight = 1;
  638. _ll_day.setLayoutParams(_llpd);
  639. // = = = = = = = = = = = = = = = = =
  640. _ll_day.addView(_tv_day);
  641. return _ll_day;
  642. }
  643. // Строка расписания Middle
  644. private LinearLayout createMiddle(JSONObject data) throws JSONException {
  645. LinearLayout _pair_row = new LinearLayout(this);
  646. LinearLayout _ll_pair = new LinearLayout(this);
  647. LinearLayout _ll_desc = new LinearLayout(this);
  648. LinearLayout _ll_disc = new LinearLayout(this);
  649. LinearLayout _ll_lect = new LinearLayout(this);
  650. _pair_row.setOrientation(LinearLayout.VERTICAL);
  651. _ll_disc.setOrientation(LinearLayout.VERTICAL);
  652. _ll_lect.setOrientation(LinearLayout.VERTICAL);
  653. _ll_pair.setOrientation(LinearLayout.HORIZONTAL);
  654. _ll_desc.setOrientation(LinearLayout.HORIZONTAL);
  655. TextView _tv_day = new TextView(this);
  656. TextView _tv_pair = new TextView(this);
  657. TextView _tv_disc = new TextView(this);
  658. TextView _tv_teacher = new TextView(this);
  659. TextView _tv_lect = new TextView(this);
  660. final Typeface faceReg = ResourcesCompat.getFont(this, R.font.play_regular);
  661. TableRow.LayoutParams _lp_pair = new TableRow.LayoutParams(40, TableRow.LayoutParams.MATCH_PARENT);
  662. _tv_pair.setText(data.getString("Pair"));
  663. _tv_pair.setTypeface(faceReg);
  664. _tv_pair.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
  665. _tv_pair.setLayoutParams(_lp_pair);
  666. _tv_pair.setTextColor(getResources().getColor(R.color.colorBlack));
  667. _tv_pair.setGravity(Gravity.CENTER);
  668. TableRow.LayoutParams _lp_lect = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
  669. _lp_lect.weight = 1;
  670. _tv_lect.setText(data.getString("Lecture"));
  671. _tv_lect.setTypeface(faceReg);
  672. _tv_lect.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
  673. _tv_lect.setLayoutParams(_lp_lect);
  674. // _tv_lect.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
  675. _tv_lect.setTextColor(getResources().getColor(R.color.colorBlack));
  676. _tv_lect.setGravity(Gravity.CENTER | Gravity.END);
  677. TableRow.LayoutParams _lp_disc = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
  678. _lp_disc.weight = 1;
  679. _tv_disc.setText(data.getString("Discipline"));
  680. _tv_disc.setTypeface(faceReg);
  681. _tv_disc.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
  682. _tv_disc.setLayoutParams(_lp_disc);
  683. _tv_disc.setHeight(52);
  684. _tv_disc.setShadowLayer(5, 0, 0, R.color.colorBlack);
  685. _tv_disc.setTextColor(getResources().getColor(R.color.colorBlack));
  686. TableRow.LayoutParams _lp_teacher = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
  687. _lp_teacher.weight = 1;
  688. _tv_teacher.setText(data.getString("Teacher"));
  689. _tv_teacher.setTypeface(faceReg, Typeface.ITALIC);
  690. _tv_teacher.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
  691. _tv_teacher.setLayoutParams(_lp_teacher);
  692. _tv_teacher.setTextColor(getResources().getColor(R.color.colorTeacher));
  693. LinearLayout.LayoutParams _llpdi = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  694. _llpdi.weight = 1;
  695. _ll_disc.setLayoutParams(_llpdi);
  696. LinearLayout.LayoutParams _llpp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  697. _llpp.weight = 1;
  698. _ll_pair.setLayoutParams(_llpp);
  699. _ll_pair.setBackground(getResources().getDrawable(R.drawable.shcedule_background));
  700. LinearLayout.LayoutParams _llpds = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  701. _llpds.weight = 1;
  702. _llpds.setMargins(4, 4, 4, 4);
  703. _ll_desc.setLayoutParams(_llpds);
  704. _ll_desc.setBackground(getResources().getDrawable(R.drawable.schedulet_discipline));
  705. _ll_desc.setPadding(4, 4, 4, 4);
  706. LinearLayout.LayoutParams _llpl = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  707. _llpl.weight = 5;
  708. _ll_lect.setLayoutParams(_llpl);
  709. LinearLayout.LayoutParams _llpd = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  710. _llpd.weight = 1;
  711. _pair_row.setLayoutParams(_llpd);
  712. // = = = = = = = = = = = = = = = = =
  713. _ll_lect.addView(_tv_lect);
  714. _ll_disc.addView(_tv_disc);
  715. _ll_disc.addView(_tv_teacher);
  716. _ll_desc.addView(_ll_disc);
  717. _ll_desc.addView(_ll_lect);
  718. _ll_pair.addView(_tv_pair);
  719. _ll_pair.addView(_ll_desc);
  720. _pair_row.addView(_ll_pair);
  721. return _pair_row;
  722. }
  723. // Строка расписания Left
  724. private LinearLayout createLeft(JSONObject data) throws JSONException {
  725. LinearLayout _pair_row = new LinearLayout(this);
  726. LinearLayout _ll_pair = new LinearLayout(this);
  727. LinearLayout _ll_desc = new LinearLayout(this);
  728. LinearLayout _ll_desc_null = new LinearLayout(this);
  729. LinearLayout _ll_disc = new LinearLayout(this);
  730. LinearLayout _ll_lect = new LinearLayout(this);
  731. _pair_row.setOrientation(LinearLayout.VERTICAL);
  732. _ll_disc.setOrientation(LinearLayout.VERTICAL);
  733. _ll_lect.setOrientation(LinearLayout.VERTICAL);
  734. _ll_pair.setOrientation(LinearLayout.HORIZONTAL);
  735. _ll_desc.setOrientation(LinearLayout.HORIZONTAL);
  736. _ll_desc_null.setOrientation(LinearLayout.HORIZONTAL);
  737. TextView _tv_day = new TextView(this);
  738. TextView _tv_pair = new TextView(this);
  739. TextView _tv_disc = new TextView(this);
  740. TextView _tv_teacher = new TextView(this);
  741. TextView _tv_lect = new TextView(this);
  742. final Typeface faceReg = ResourcesCompat.getFont(this, R.font.play_regular);
  743. TableRow.LayoutParams _lp_pair = new TableRow.LayoutParams(40, TableRow.LayoutParams.MATCH_PARENT);
  744. _tv_pair.setText(data.getString("Pair"));
  745. _tv_pair.setTypeface(faceReg);
  746. _tv_pair.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
  747. _tv_pair.setLayoutParams(_lp_pair);
  748. _tv_pair.setTextColor(getResources().getColor(R.color.colorBlack));
  749. _tv_pair.setGravity(Gravity.CENTER);
  750. TableRow.LayoutParams _lp_lect = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
  751. _lp_lect.weight = 1;
  752. _tv_lect.setText(data.getString("Lecture"));
  753. _tv_lect.setTypeface(faceReg);
  754. _tv_lect.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
  755. _tv_lect.setLayoutParams(_lp_lect);
  756. // _tv_lect.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
  757. _tv_lect.setTextColor(getResources().getColor(R.color.colorBlack));
  758. _tv_lect.setGravity(Gravity.CENTER);
  759. TableRow.LayoutParams _lp_disc = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
  760. _lp_disc.weight = 1;
  761. _tv_disc.setText(data.getString("Discipline"));
  762. _tv_disc.setTypeface(faceReg);
  763. _tv_disc.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
  764. _tv_disc.setLayoutParams(_lp_disc);
  765. _tv_disc.setHeight(52);
  766. _tv_disc.setShadowLayer(5, 0, 0, R.color.colorBlack);
  767. _tv_disc.setTextColor(getResources().getColor(R.color.colorBlack));
  768. TableRow.LayoutParams _lp_teacher = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
  769. _lp_teacher.weight = 1;
  770. _tv_teacher.setText(data.getString("Teacher"));
  771. _tv_teacher.setTypeface(faceReg, Typeface.ITALIC);
  772. _tv_teacher.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
  773. _tv_teacher.setLayoutParams(_lp_teacher);
  774. _tv_teacher.setTextColor(getResources().getColor(R.color.colorTeacher));
  775. LinearLayout.LayoutParams _llpdi = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  776. _llpdi.weight = 1;
  777. _ll_disc.setLayoutParams(_llpdi);
  778. LinearLayout.LayoutParams _llpp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  779. _llpp.weight = 1;
  780. _ll_pair.setLayoutParams(_llpp);
  781. _ll_pair.setBackground(getResources().getDrawable(R.drawable.shcedule_background));
  782. LinearLayout.LayoutParams _llpds = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  783. _llpds.weight = 1;
  784. _llpds.setMargins(4, 4, 2, 4);
  785. _ll_desc.setLayoutParams(_llpds);
  786. _ll_desc.setBackground(getResources().getDrawable(R.drawable.schedulet_discipline));
  787. _ll_desc.setPadding(4, 4, 4, 4);
  788. LinearLayout.LayoutParams _llpdsn = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  789. _llpdsn.weight = 1;
  790. _llpdsn.setMargins(2, 4, 4, 4);
  791. _ll_desc_null.setLayoutParams(_llpds);
  792. _ll_desc_null.setBackground(getResources().getDrawable(R.drawable.schedulet_discipline));
  793. _ll_desc_null.setPadding(4, 4, 4, 4);
  794. LinearLayout.LayoutParams _llpl = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  795. _llpl.weight = 5;
  796. _ll_lect.setLayoutParams(_llpl);
  797. LinearLayout.LayoutParams _llpd = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  798. _llpd.weight = 1;
  799. _pair_row.setLayoutParams(_llpd);
  800. // = = = = = = = = = = = = = = = = =
  801. _ll_lect.addView(_tv_lect);
  802. _ll_disc.addView(_tv_disc);
  803. _ll_disc.addView(_tv_teacher);
  804. _ll_desc.addView(_ll_disc);
  805. _ll_desc.addView(_ll_lect);
  806. _ll_pair.addView(_tv_pair);
  807. _ll_pair.addView(_ll_desc);
  808. _ll_pair.addView(_ll_desc_null);
  809. _pair_row.addView(_ll_pair);
  810. return _pair_row;
  811. }
  812. // Строка расписания Right
  813. private LinearLayout createRight(JSONObject data) throws JSONException {
  814. LinearLayout _pair_row = new LinearLayout(this);
  815. LinearLayout _ll_pair = new LinearLayout(this);
  816. LinearLayout _ll_desc = new LinearLayout(this);
  817. LinearLayout _ll_desc_null = new LinearLayout(this);
  818. LinearLayout _ll_disc = new LinearLayout(this);
  819. LinearLayout _ll_lect = new LinearLayout(this);
  820. _pair_row.setOrientation(LinearLayout.VERTICAL);
  821. _ll_disc.setOrientation(LinearLayout.VERTICAL);
  822. _ll_lect.setOrientation(LinearLayout.VERTICAL);
  823. _ll_pair.setOrientation(LinearLayout.HORIZONTAL);
  824. _ll_desc.setOrientation(LinearLayout.HORIZONTAL);
  825. _ll_desc_null.setOrientation(LinearLayout.HORIZONTAL);
  826. TextView _tv_day = new TextView(this);
  827. TextView _tv_pair = new TextView(this);
  828. TextView _tv_disc = new TextView(this);
  829. TextView _tv_teacher = new TextView(this);
  830. TextView _tv_lect = new TextView(this);
  831. final Typeface faceReg = ResourcesCompat.getFont(this, R.font.play_regular);
  832. TableRow.LayoutParams _lp_pair = new TableRow.LayoutParams(40, TableRow.LayoutParams.MATCH_PARENT);
  833. _tv_pair.setText(data.getString("Pair"));
  834. _tv_pair.setTypeface(faceReg);
  835. _tv_pair.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
  836. _tv_pair.setLayoutParams(_lp_pair);
  837. _tv_pair.setTextColor(getResources().getColor(R.color.colorBlack));
  838. _tv_pair.setGravity(Gravity.CENTER);
  839. TableRow.LayoutParams _lp_lect = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
  840. _lp_lect.weight = 1;
  841. _tv_lect.setText(data.getString("Lecture"));
  842. _tv_lect.setTypeface(faceReg);
  843. _tv_lect.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
  844. _tv_lect.setLayoutParams(_lp_lect);
  845. // _tv_lect.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
  846. _tv_lect.setTextColor(getResources().getColor(R.color.colorBlack));
  847. _tv_lect.setGravity(Gravity.CENTER);
  848. TableRow.LayoutParams _lp_disc = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
  849. _lp_disc.weight = 1;
  850. _tv_disc.setText(data.getString("Discipline"));
  851. _tv_disc.setTypeface(faceReg);
  852. _tv_disc.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
  853. _tv_disc.setLayoutParams(_lp_disc);
  854. _tv_disc.setHeight(52);
  855. _tv_disc.setShadowLayer(5, 0, 0, R.color.colorBlack);
  856. _tv_disc.setTextColor(getResources().getColor(R.color.colorBlack));
  857. TableRow.LayoutParams _lp_teacher = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
  858. _lp_teacher.weight = 1;
  859. _tv_teacher.setText(data.getString("Teacher"));
  860. _tv_teacher.setTypeface(faceReg, Typeface.ITALIC);
  861. _tv_teacher.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
  862. _tv_teacher.setLayoutParams(_lp_teacher);
  863. _tv_teacher.setTextColor(getResources().getColor(R.color.colorTeacher));
  864. LinearLayout.LayoutParams _llpdi = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  865. _llpdi.weight = 1;
  866. _ll_disc.setLayoutParams(_llpdi);
  867. LinearLayout.LayoutParams _llpp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  868. _llpp.weight = 1;
  869. _ll_pair.setLayoutParams(_llpp);
  870. _ll_pair.setBackground(getResources().getDrawable(R.drawable.shcedule_background));
  871. LinearLayout.LayoutParams _llpds = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  872. _llpds.weight = 1;
  873. _llpds.setMargins(4, 4, 2, 4);
  874. _ll_desc.setLayoutParams(_llpds);
  875. _ll_desc.setBackground(getResources().getDrawable(R.drawable.schedulet_discipline));
  876. _ll_desc.setPadding(4, 4, 4, 4);
  877. LinearLayout.LayoutParams _llpdsn = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  878. _llpdsn.weight = 1;
  879. _llpdsn.setMargins(2, 4, 4, 4);
  880. _ll_desc_null.setLayoutParams(_llpds);
  881. _ll_desc_null.setBackground(getResources().getDrawable(R.drawable.schedulet_discipline));
  882. _ll_desc_null.setPadding(4, 4, 4, 4);
  883. LinearLayout.LayoutParams _llpl = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  884. _llpl.weight = 5;
  885. _ll_lect.setLayoutParams(_llpl);
  886. LinearLayout.LayoutParams _llpd = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  887. _llpd.weight = 1;
  888. _pair_row.setLayoutParams(_llpd);
  889. // = = = = = = = = = = = = = = = = =
  890. _ll_lect.addView(_tv_lect);
  891. _ll_disc.addView(_tv_disc);
  892. _ll_disc.addView(_tv_teacher);
  893. _ll_desc.addView(_ll_disc);
  894. _ll_desc.addView(_ll_lect);
  895. _ll_pair.addView(_tv_pair);
  896. _ll_pair.addView(_ll_desc_null);
  897. _ll_pair.addView(_ll_desc);
  898. _pair_row.addView(_ll_pair);
  899. return _pair_row;
  900. }
  901. // Строка расписания Both
  902. private LinearLayout createBoth(JSONObject dataL, JSONObject dataR) throws JSONException {
  903. LinearLayout _pair_row = new LinearLayout(this);
  904. LinearLayout _ll_pair = new LinearLayout(this);
  905. LinearLayout _ll_desc = new LinearLayout(this);
  906. LinearLayout _ll_desc_r = new LinearLayout(this);
  907. LinearLayout _ll_disc = new LinearLayout(this);
  908. LinearLayout _ll_disc_r = new LinearLayout(this);
  909. LinearLayout _ll_lect = new LinearLayout(this);
  910. LinearLayout _ll_lect_r = new LinearLayout(this);
  911. _pair_row.setOrientation(LinearLayout.VERTICAL);
  912. _ll_disc.setOrientation(LinearLayout.VERTICAL);
  913. _ll_lect.setOrientation(LinearLayout.VERTICAL);
  914. _ll_disc_r.setOrientation(LinearLayout.VERTICAL);
  915. _ll_lect_r.setOrientation(LinearLayout.VERTICAL);
  916. _ll_pair.setOrientation(LinearLayout.HORIZONTAL);
  917. _ll_desc.setOrientation(LinearLayout.HORIZONTAL);
  918. _ll_desc_r.setOrientation(LinearLayout.HORIZONTAL);
  919. TextView _tv_day = new TextView(this);
  920. TextView _tv_pair = new TextView(this);
  921. TextView _tv_disc = new TextView(this);
  922. TextView _tv_teacher = new TextView(this);
  923. TextView _tv_lect = new TextView(this);
  924. TextView _tv_disc_r = new TextView(this);
  925. TextView _tv_teacher_r = new TextView(this);
  926. TextView _tv_lect_r = new TextView(this);
  927. final Typeface faceReg = ResourcesCompat.getFont(this, R.font.play_regular);
  928. TableRow.LayoutParams _lp_pair = new TableRow.LayoutParams(40, TableRow.LayoutParams.MATCH_PARENT);
  929. _tv_pair.setText(dataL.getString("Pair"));
  930. _tv_pair.setTypeface(faceReg);
  931. _tv_pair.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
  932. _tv_pair.setLayoutParams(_lp_pair);
  933. _tv_pair.setTextColor(getResources().getColor(R.color.colorBlack));
  934. _tv_pair.setGravity(Gravity.CENTER);
  935. TableRow.LayoutParams _lp_lect = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
  936. _lp_lect.weight = 1;
  937. _tv_lect.setText(dataL.getString("Lecture"));
  938. _tv_lect.setTypeface(faceReg);
  939. _tv_lect.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
  940. _tv_lect.setLayoutParams(_lp_lect);
  941. // _tv_lect.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
  942. _tv_lect.setTextColor(getResources().getColor(R.color.colorBlack));
  943. _tv_lect.setGravity(Gravity.CENTER);
  944. TableRow.LayoutParams _lp_lect_r = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
  945. _lp_lect_r.weight = 1;
  946. _tv_lect_r.setText(dataL.getString("Lecture"));
  947. _tv_lect_r.setTypeface(faceReg);
  948. _tv_lect_r.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
  949. _tv_lect_r.setLayoutParams(_lp_lect_r);
  950. // _tv_lect_r.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
  951. _tv_lect_r.setTextColor(getResources().getColor(R.color.colorBlack));
  952. _tv_lect_r.setGravity(Gravity.CENTER);
  953. TableRow.LayoutParams _lp_disc = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
  954. _lp_disc.weight = 1;
  955. _tv_disc.setText(dataL.getString("Discipline"));
  956. _tv_disc.setTypeface(faceReg);
  957. _tv_disc.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
  958. _tv_disc.setLayoutParams(_lp_disc);
  959. _tv_disc.setHeight(52);
  960. _tv_disc.setShadowLayer(5, 0, 0, R.color.colorBlack);
  961. _tv_disc.setTextColor(getResources().getColor(R.color.colorBlack));
  962. TableRow.LayoutParams _lp_disc_r = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
  963. _lp_disc_r.weight = 1;
  964. _tv_disc_r.setText(dataL.getString("Discipline"));
  965. _tv_disc_r.setTypeface(faceReg);
  966. _tv_disc_r.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
  967. _tv_disc_r.setLayoutParams(_lp_disc_r);
  968. _tv_disc_r.setHeight(52);
  969. _tv_disc_r.setShadowLayer(5, 0, 0, R.color.colorBlack);
  970. _tv_disc_r.setTextColor(getResources().getColor(R.color.colorBlack));
  971. TableRow.LayoutParams _lp_teacher = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
  972. _lp_teacher.weight = 1;
  973. _tv_teacher.setText(dataL.getString("Teacher"));
  974. _tv_teacher.setTypeface(faceReg, Typeface.ITALIC);
  975. _tv_teacher.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
  976. _tv_teacher.setLayoutParams(_lp_teacher);
  977. _tv_teacher.setTextColor(getResources().getColor(R.color.colorTeacher));
  978. TableRow.LayoutParams _lp_teacher_r = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
  979. _lp_teacher_r.weight = 1;
  980. _tv_teacher_r.setText(dataL.getString("Teacher"));
  981. _tv_teacher_r.setTypeface(faceReg, Typeface.ITALIC);
  982. _tv_teacher_r.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
  983. _tv_teacher_r.setLayoutParams(_lp_teacher_r);
  984. _tv_teacher_r.setTextColor(getResources().getColor(R.color.colorTeacher));
  985. LinearLayout.LayoutParams _llpdi = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  986. _llpdi.weight = 1;
  987. _ll_disc.setLayoutParams(_llpdi);
  988. LinearLayout.LayoutParams _llpdi_r = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  989. _llpdi_r.weight = 1;
  990. _ll_disc_r.setLayoutParams(_llpdi_r);
  991. LinearLayout.LayoutParams _llpp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  992. _llpp.weight = 1;
  993. _ll_pair.setLayoutParams(_llpp);
  994. _ll_pair.setBackground(getResources().getDrawable(R.drawable.shcedule_background));
  995. LinearLayout.LayoutParams _llpds = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  996. _llpds.weight = 1;
  997. _llpds.setMargins(4, 4, 2, 4);
  998. _ll_desc.setLayoutParams(_llpds);
  999. _ll_desc.setBackground(getResources().getDrawable(R.drawable.schedulet_discipline));
  1000. _ll_desc.setPadding(4, 4, 4, 4);
  1001. LinearLayout.LayoutParams _llpdsn = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  1002. _llpdsn.weight = 1;
  1003. _llpdsn.setMargins(2, 4, 4, 4);
  1004. _ll_desc_r.setLayoutParams(_llpds);
  1005. _ll_desc_r.setBackground(getResources().getDrawable(R.drawable.schedulet_discipline));
  1006. _ll_desc_r.setPadding(4, 4, 4, 4);
  1007. LinearLayout.LayoutParams _llpl = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  1008. _llpl.weight = 5;
  1009. _ll_lect.setLayoutParams(_llpl);
  1010. LinearLayout.LayoutParams _llpl_r = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
  1011. _llpl_r.weight = 5;
  1012. _ll_lect_r.setLayoutParams(_llpl);
  1013. LinearLayout.LayoutParams _llpd = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  1014. _llpd.weight = 1;
  1015. _pair_row.setLayoutParams(_llpd);
  1016. // = = = = = = = = = = = = = = = = =
  1017. _ll_lect.addView(_tv_lect);
  1018. _ll_disc.addView(_tv_disc);
  1019. _ll_disc.addView(_tv_teacher);
  1020. _ll_desc.addView(_ll_disc);
  1021. _ll_desc.addView(_ll_lect);
  1022. _ll_lect_r.addView(_tv_lect_r);
  1023. _ll_disc_r.addView(_tv_disc_r);
  1024. _ll_disc_r.addView(_tv_teacher_r);
  1025. _ll_desc_r.addView(_ll_disc_r);
  1026. _ll_desc_r.addView(_ll_lect_r);
  1027. _ll_pair.addView(_tv_pair);
  1028. _ll_pair.addView(_ll_desc);
  1029. _ll_pair.addView(_ll_desc_r);
  1030. _pair_row.addView(_ll_pair);
  1031. return _pair_row;
  1032. }
  1033. }