Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.51 KB | None | 0 0
  1. public class DemoDragment extends Fragment implements SurfaceHolder.Callback, View.OnClickListener {
  2.  
  3. private RecyclerView recyclerView;
  4. private OnFragmentInteractionListener mListener;
  5. public static HomeVideoListener homeVideoListener;
  6. public static SurfaceView surfaceView;
  7. public static ImageView playIcon;
  8. public static boolean homePlayClicked;
  9. public static LastSeenChannelHomeResponse.RootEntity rootEntity;
  10. public static String playURL = "";
  11. SharedPreferences sharedpreferences;
  12. boolean checkRate = false;
  13. SharedPreferences.Editor editor;
  14. private String customerUniqueId, version;
  15. private JSONCallback updateCall;
  16. private Context context;
  17. private Activity activityContext;
  18. private TextView logoutTV, backButtonTV, titleTV, mainHomeTV;
  19. private Uri contentUri;
  20. private ImageView titleImageView;
  21. private ImageView logoImageButton;
  22. private RelativeLayout actionbarLayout;
  23. private RelativeLayout mainRelativeLayout;
  24. private GestureDetector gestureDetector;
  25. private View.OnTouchListener gestureListener;
  26. private PercentRelativeLayout surfaceLayout;
  27. public static boolean playingVideo;
  28. private boolean checkNowClick = false, isCancelled = false, playerNeedsPrepare;
  29. public static final int TYPE_HLS = 2;
  30. private int contentType = TYPE_HLS;
  31. private CustomPlayer player;
  32. private AudioCapabilitiesReceiver audioCapabilitiesReceiver;
  33. private long playerPosition;
  34. private EventLogger eventLogger;
  35. public static MediaController.MediaPlayerControl mediaControl;
  36. private long timeToPlay = 0;
  37. private LinearLayout channelControls;
  38. public static String countryCodeValue;
  39. private String mcc, mnc, ipAddress, strDate, getChannelDataURLNew, timeZone;
  40. private int swipeGesturePosition = 0;
  41. private boolean isPaused = false, isPlaying = true;
  42. GestureDetector mGestureDetector;
  43. private ImageButton onDemandBack;
  44.  
  45. public DemoFragment() {
  46. // Required empty public constructor
  47. }
  48.  
  49. @Override
  50. public void onCreate(Bundle savedInstanceState) {
  51. super.onCreate(savedInstanceState);
  52. if (getArguments() != null) {
  53.  
  54. }
  55.  
  56. }
  57.  
  58. @Override
  59. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  60. Bundle savedInstanceState) {
  61. // Inflate the layout for this fragment
  62. View view = inflater.inflate(R.layout.fragment_demo, container, false);
  63.  
  64. playingVideo = false;
  65.  
  66. context = getActivity();
  67. activityContext = getActivity();
  68. homeVideoListener = new HomeVideoListener(activityContext);
  69. version = android.os.Build.VERSION.RELEASE;
  70. sharedpreferences = PreferenceManager
  71. .getDefaultSharedPreferences(context);
  72.  
  73. editor = sharedpreferences.edit();
  74. customerUniqueId = sharedpreferences.getString(Constants.PREF_CUSTOMER_UNIQ, null);
  75. playIcon = (ImageView) view.findViewById(R.id.play_icon);
  76.  
  77. surfaceLayout = (PercentRelativeLayout) getActivity().findViewById(R.id.surface_view);
  78.  
  79. surfaceView = (SurfaceView) view.findViewById(R.id.home_image);
  80.  
  81. recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
  82. channelControls = (LinearLayout)view.findViewById(R.id.linear_recycler);
  83.  
  84. DemoFragment = (DemoFragment) this;
  85. Bundle args = fragment.getArguments();
  86. int pos = 0;
  87. int appPos=0;
  88. if (args != null) {
  89. pos = args.getInt("id");
  90. appPos = args.getInt("id");
  91. // Toast.makeText(getActivity(), "Getting position in DemoFragment:" + pos, Toast.LENGTH_SHORT).show();
  92. }
  93.  
  94. // this is data fro recycler view
  95. ItemData itemsData[] = {new ItemData(R.drawable.app_launch_icon),
  96. new ItemData(R.drawable.app_launch_icon),
  97. new ItemData(R.drawable.blank_box),
  98. new ItemData(R.drawable.blank_box)};
  99.  
  100. // 2. set layoutManger
  101. recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
  102. // 3. create an adapter
  103. MyAdapter mAdapter = new MyAdapter(itemsData, (AutomateActivity) getActivity(), pos, appPos);
  104. // 4. set adapter
  105. recyclerView.setAdapter(mAdapter);
  106.  
  107. gestureListener = new View.OnTouchListener() {
  108. public boolean onTouch(View v, MotionEvent event) {
  109. playIcon.setVisibility(View.VISIBLE);
  110. new Handler().postDelayed(new Runnable() {
  111. public void run() {
  112. if (homePlayClicked) {
  113. playIcon.setVisibility(View.GONE);
  114. }
  115. }
  116. }, 5 * 1000);
  117. return true;
  118. }
  119. };
  120.  
  121. surfaceView.setOnTouchListener(gestureListener);
  122. playIcon.setOnClickListener(this);
  123. homePlayClicked = true;
  124. return view;
  125. }
  126.  
  127.  
  128.  
  129. MyAdapter.java
  130.  
  131. public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
  132.  
  133. private ItemData[] itemsData;
  134. static AutomateActivity activity;
  135. static int pos;
  136. static int rowPosition;
  137.  
  138. static int appPos;
  139.  
  140.  
  141. static int roomAreaPos;
  142. static int grieviewImagePosition[] = {-1, -1, -1, -1, -1, -1};
  143.  
  144.  
  145. public MyAdapter(ItemData[] itemsData, AutomateActivity activity, int pos, int appPos) {
  146. this.itemsData = itemsData;
  147. this.activity = activity;
  148. this.pos = pos;
  149. this.appPos = appPos;
  150.  
  151.  
  152. }
  153.  
  154.  
  155. // Create new views (invoked by the layout manager)
  156. @Override
  157. public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
  158. int viewType) {
  159. // create a new view
  160. View itemLayoutView = LayoutInflater.from(parent.getContext())
  161. .inflate(R.layout.listview_layout, null);
  162.  
  163. // create ViewHolder
  164.  
  165. ViewHolder viewHolder = new ViewHolder(itemLayoutView);
  166. return viewHolder;
  167. }
  168.  
  169. // Replace the contents of a view (invoked by the layout manager)
  170. @Override
  171. public void onBindViewHolder(final ViewHolder viewHolder, final int position) {
  172.  
  173. // - get data from your itemsData at this position
  174. // - replace the contents of the view with that itemsData
  175.  
  176. if (roomAreaPos == position) {
  177.  
  178.  
  179. grieviewImagePosition[position] = pos;
  180.  
  181.  
  182. }
  183.  
  184. if (grieviewImagePosition[position] != -1) {
  185. viewHolder.imgViewIcon.setVisibility(View.VISIBLE);
  186.  
  187. viewHolder.imgViewIcon.setImageResource(AutomateRoomsFragment.automateRooms[grieviewImagePosition[position]]);
  188.  
  189.  
  190. if (roomAreaPos == position) {
  191.  
  192.  
  193. grieviewImagePosition[position] = pos;
  194. }
  195. }
  196.  
  197.  
  198. viewHolder.imgViewIcon.setOnClickListener(new View.OnClickListener() {
  199. public void onClick(View view) {
  200. switch (position) {
  201. case 0:
  202. break;
  203. }
  204. }
  205. });
  206.  
  207. viewHolder.rLayout.setOnClickListener(new View.OnClickListener() {
  208. @Override
  209. public void onClick(View v) {
  210. // viewHolder.imgViewIcon.setVisibility(View.VISIBLE);
  211. switch (position) {
  212. case 0:
  213. roomAreaPos = position;
  214. Fragment fragment = new AutomateRoomsFragment();
  215. FragmentManager fragmentManager = activity.getSupportFragmentManager();
  216. FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
  217. fragmentTransaction.replace(R.id.main_container, fragment);
  218. fragmentTransaction.addToBackStack(null);
  219. fragmentTransaction.commit();
  220. break;
  221.  
  222. case 1:
  223. roomAreaPos = position;
  224.  
  225. Fragment fragment1 = new AutomateRoomsFragment();
  226. FragmentManager fragmentManager1 = activity.getSupportFragmentManager();
  227. FragmentTransaction fragmentTransaction1 = fragmentManager1.beginTransaction();
  228. fragmentTransaction1.replace(R.id.main_container, fragment1);
  229. fragmentTransaction1.addToBackStack(null);
  230. fragmentTransaction1.commit();
  231. break;
  232.  
  233. case 2:
  234. roomAreaPos = position;
  235.  
  236. Fragment fragment2 = new AutomateRoomsFragment();
  237. FragmentManager fragmentManager2 = activity.getSupportFragmentManager();
  238. FragmentTransaction fragmentTransaction2 = fragmentManager2.beginTransaction();
  239. fragmentTransaction2.replace(R.id.main_container, fragment2);
  240. fragmentTransaction2.addToBackStack(null);
  241. fragmentTransaction2.commit();
  242. break;
  243.  
  244. case 3:
  245. roomAreaPos = position;
  246. Fragment fragment3 = new AutomateRoomsFragment();
  247. FragmentManager fragmentManager3 = activity.getSupportFragmentManager();
  248. FragmentTransaction fragmentTransaction3 = fragmentManager3.beginTransaction();
  249. fragmentTransaction3.replace(R.id.main_container, fragment3);
  250. fragmentTransaction3.addToBackStack(null);
  251. fragmentTransaction3.commit();
  252. break;
  253.  
  254.  
  255. }
  256.  
  257.  
  258. }
  259.  
  260. });
  261.  
  262. }
  263.  
  264.  
  265. // inner class to hold a reference to each item of RecyclerView
  266. public static class ViewHolder extends RecyclerView.ViewHolder {
  267.  
  268. public ImageView imgViewIcon;
  269. public RelativeLayout rLayout;
  270. private MyAdapter mParent;
  271.  
  272. public ImageView appImgOne, appImgTwo, appImageThree, appImageFour;
  273.  
  274. static boolean DeviceDisplay = false;
  275.  
  276. public ViewHolder(View itemLayoutView) {
  277. super(itemLayoutView);
  278.  
  279. itemView.setOnClickListener(new View.OnClickListener() {
  280.  
  281.  
  282. @Override
  283. public void onClick(View v) {
  284.  
  285. int itemPosition = getAdapterPosition();
  286.  
  287. rowPosition = itemPosition;
  288.  
  289. Toast.makeText(activity, "Row position inside switch case:" + rowPosition, Toast.LENGTH_SHORT).show();
  290.  
  291.  
  292.  
  293.  
  294.  
  295. Fragment fragment = new AutomateAppliancesFragment();
  296. FragmentManager fragmentManager = activity.getSupportFragmentManager();
  297. FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
  298. fragmentTransaction.replace(R.id.main_container, fragment);
  299. fragmentTransaction.addToBackStack(null);
  300. fragmentTransaction.commit();
  301. /* appImgOne.setVisibility(View.VISIBLE);
  302. appImgOne.setImageResource(AutomateAppliancesFragment.appliances[pos]);*/
  303.  
  304. }
  305. });
  306.  
  307.  
  308. this.imgViewIcon = (ImageView) itemLayoutView.findViewById(R.id.icon);
  309. this.rLayout = (RelativeLayout) itemLayoutView.findViewById(R.id.btn_circle_one);
  310. Resources res = itemLayoutView.getResources(); //resource handle
  311. Drawable drawable = res.getDrawable(R.drawable.blank_box); //new Image that was added to the res folder
  312. rLayout.setBackground(drawable);
  313.  
  314. this.appImgOne = (ImageView) itemLayoutView.findViewById(R.id.appliance_one);
  315. this.appImgTwo = (ImageView) itemLayoutView.findViewById(R.id.appliance_two);
  316. this.appImageThree = (ImageView) itemLayoutView.findViewById(R.id.appliance_three);
  317. this.appImageFour = (ImageView) itemLayoutView.findViewById(R.id.appliance_four);
  318. switch (rowPosition) {
  319.  
  320. case 0:
  321. if ( appImgOne.getVisibility() == View.GONE) {
  322. appImgOne.setImageResource(AutomateAppliancesFragment.appliances[appPos]);
  323. appImgOne.setVisibility(View.VISIBLE);
  324. }
  325. }
  326. }
  327. // Return the size of your itemsData (invoked by the layout manager)
  328. @Override
  329. public int getItemCount() {
  330. return itemsData.length;
  331. }}
  332.  
  333. listview_layout.xml
  334.  
  335. <?xml version="1.0" encoding="utf-8"?>
  336. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  337. android:layout_width="match_parent"
  338. android:layout_height="wrap_content"
  339. android:background="#FFFFFF"
  340. android:clickable="true"
  341. android:focusable="true">
  342.  
  343.  
  344.  
  345.  
  346. <RelativeLayout
  347. android:id="@+id/btn_circle_one"
  348. android:layout_width="60dp"
  349. android:layout_height="50dp"
  350. android:layout_marginTop="3dp">
  351.  
  352. <ImageView
  353. android:id="@+id/icon"
  354. android:layout_width="40dp"
  355. android:layout_height="40dp"
  356. android:layout_alignParentTop="true"
  357. android:layout_marginBottom="@dimen/margin_1"
  358. android:layout_marginLeft="@dimen/margin_medium"
  359. android:layout_marginTop="@dimen/margin_1"
  360. android:adjustViewBounds="false"
  361. android:background="@drawable/image_background"
  362. android:paddingBottom="@dimen/margin_2"
  363. android:paddingLeft="@dimen/margin_small"
  364. android:paddingRight="@dimen/margin_small"
  365. android:paddingTop="@dimen/margin_2"
  366. android:scaleType="fitCenter"
  367. android:visibility="gone"/>
  368.  
  369.  
  370.  
  371.  
  372. </RelativeLayout>
  373.  
  374.  
  375. <View
  376. android:layout_width="match_parent"
  377. android:layout_height="@dimen/line_height"
  378. android:layout_below="@id/btn_circle_one"
  379. android:layout_marginLeft="@dimen/margin_four"
  380. android:layout_marginRight="@dimen/margin_four"
  381. android:layout_marginTop="12dp"
  382. android:background="@color/separator_color"
  383. android:id="@+id/view" />
  384. <RelativeLayout
  385. android:id="@+id/relative"
  386. android:layout_width="match_parent"
  387. android:layout_height="match_parent"
  388. android:layout_above="@+id/view"
  389. android:layout_alignLeft="@+id/view"
  390. android:layout_alignStart="@+id/view">
  391.  
  392. <ImageView
  393. android:layout_width="50dp"
  394. android:layout_height="50dp"
  395. android:id="@+id/appliance_one"
  396. android:src="@drawable/app_launch_icon"
  397. android:layout_toLeftOf="@+id/appliance_two"
  398. android:layout_toStartOf="@+id/appliance_two"
  399. android:layout_marginLeft="33dp"
  400. android:visibility="gone"
  401. />
  402.  
  403.  
  404. <ImageView
  405. android:layout_width="50dp"
  406. android:layout_height="50dp"
  407. android:id="@+id/appliance_two"
  408. android:src="@drawable/app_launch_icon"
  409. android:layout_alignParentTop="true"
  410. android:layout_centerHorizontal="true"
  411. android:visibility="gone"/>
  412.  
  413. <ImageView
  414. android:layout_width="50dp"
  415. android:layout_height="50dp"
  416. android:id="@+id/appliance_three"
  417. android:src="@drawable/app_launch_icon"
  418. android:layout_alignParentTop="true"
  419. android:layout_toRightOf="@+id/appliance_two"
  420. android:layout_toEndOf="@+id/appliance_two"
  421. android:visibility="gone"/>
  422.  
  423. <ImageView
  424. android:layout_width="50dp"
  425. android:layout_height="50dp"
  426. android:id="@+id/appliance_four"
  427. android:src="@drawable/app_launch_icon"
  428. android:layout_alignParentTop="true"
  429. android:layout_toRightOf="@+id/appliance_three"
  430. android:layout_toEndOf="@+id/appliance_three"
  431. android:visibility="gone"/>
  432.  
  433.  
  434.  
  435. </RelativeLayout>
  436.  
  437. Can someone please help me to resolve this issue ASAP.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement