Guest User

Untitled

a guest
Nov 17th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.28 KB | None | 0 0
  1. @Override
  2. public void onInfoSelected() {
  3.  
  4. abf = (AboutFragment) getSupportFragmentManager().findFragmentByTag(ABOUT_FRAGMENT_TAG);
  5.  
  6. FragmentTransaction ft = fm.beginTransaction();
  7. ft.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right,
  8. android.R.anim.slide_in_left, android.R.anim.slide_out_right);
  9. // ft.hide(pf);
  10.  
  11. //ft.hide(cf);
  12. ft.hide(tlf);
  13. ft.show(abf);
  14. ft.addToBackStack(null);
  15. ft.commit();
  16. }
  17.  
  18. package me.declangao.jiasazsales.app;
  19.  
  20. import android.content.Intent;
  21. import android.os.Bundle;
  22. import android.support.v4.app.FragmentManager;
  23. import android.support.v4.app.FragmentTransaction;
  24. import android.support.v7.app.AppCompatActivity;
  25. import android.util.Log;
  26. import android.view.Menu;
  27. import android.view.MenuItem;
  28.  
  29. import me.declangao.jiasazsales.R;
  30. import me.declangao.jiasazsales.model.Post;
  31.  
  32. public class MainActivity extends AppCompatActivity implements
  33. RecyclerViewFragment.PostListListener, PostFragment.PostListener,
  34. TabLayoutFragment.TabLayoutListener, SearchResultFragment.SearchResultListener,
  35. CommentFragment.CommentListener,AboutFragment.AboutListener {
  36.  
  37. private static final String TAG = MainActivity.class.getSimpleName();
  38. public static final String TAB_LAYOUT_FRAGMENT_TAG = "TabLayoutFragment";
  39. public static final String POST_FRAGMENT_TAG = "PostFragment";
  40. public static final String COMMENT_FRAGMENT_TAG = "CommentFragment";
  41.  
  42. public static final String ABOUT_FRAGMENT_TAG = "AboutFragment";
  43.  
  44.  
  45. private FragmentManager fm = null;
  46. private TabLayoutFragment tlf;
  47. private PostFragment pf;
  48. private CommentFragment cf;
  49. private SearchResultFragment srf;
  50. private AboutFragment abf;
  51.  
  52.  
  53. @Override
  54. protected void onCreate(Bundle savedInstanceState) {
  55. super.onCreate(savedInstanceState);
  56. //setContentView(R.layout.activity_main);
  57.  
  58.  
  59.  
  60. fm = getSupportFragmentManager();
  61.  
  62. // Setup fragments
  63. tlf = new TabLayoutFragment();
  64. pf = new PostFragment();
  65. cf = new CommentFragment();
  66. srf = new SearchResultFragment();
  67. abf=new AboutFragment();
  68. FragmentTransaction ft = fm.beginTransaction();
  69. ft.add(android.R.id.content, abf, ABOUT_FRAGMENT_TAG);
  70. ft.add(android.R.id.content, pf, POST_FRAGMENT_TAG);
  71. ft.add(android.R.id.content, cf, COMMENT_FRAGMENT_TAG);
  72. ft.add(android.R.id.content, tlf, TAB_LAYOUT_FRAGMENT_TAG);
  73.  
  74.  
  75. ft.hide(pf);
  76. ft.hide(cf);
  77. ft.hide(abf);
  78. ft.show(tlf);
  79. ft.commit();
  80. }
  81.  
  82. /**
  83. * Invoked when a post in the list is selected
  84. *
  85. * @param post Selected Post object
  86. */
  87. @Override
  88. public void onPostSelected(Post post, boolean isSearch) {
  89. // Find the fragment in order to set it up later
  90. pf = (PostFragment) getSupportFragmentManager().findFragmentByTag(POST_FRAGMENT_TAG);
  91.  
  92. // Set necessary arguments
  93. Bundle args = new Bundle();
  94. args.putInt("id", post.getId());
  95. args.putString("title", post.getTitle());
  96. args.putString("date", post.getDate());
  97. args.putString("author", post.getAuthor());
  98. args.putString("content", post.getContent());
  99. args.putString("url", post.getUrl());
  100. //args.putString("thumbnailUrl", post.getThumbnailUrl());
  101. args.putString("featuredImage", post.getFeaturedImageUrl());
  102.  
  103. // Configure PostFragment to display the right post
  104. pf.setUIArguments(args);
  105.  
  106. // Show the fragment
  107. FragmentTransaction ft = fm.beginTransaction();
  108. ft.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right,
  109. android.R.anim.slide_in_left, android.R.anim.slide_out_right);
  110. if (!isSearch) { // Hide TabLayoutFragment if this is not search result
  111. ft.hide(tlf);
  112.  
  113. } else { // Otherwise, hide the search result, ie. SearchResultFragment.
  114. ft.hide(srf);
  115. }
  116. ft.show(pf);
  117. ft.addToBackStack(null);
  118. ft.commit();
  119. }
  120. @Override
  121. public boolean onOptionsItemSelected(MenuItem item) {
  122. switch (item.getItemId()) {
  123. case android.R.id.home:
  124. //do something here like
  125. Log.e("menu Test","rom Main activity");
  126. int backStackEntryCount
  127. =getSupportFragmentManager().getBackStackEntryCount();
  128.  
  129. if (backStackEntryCount > 0) {
  130.  
  131. getSupportFragmentManager().popBackStack();
  132.  
  133. }
  134.  
  135. return true;
  136. }
  137. return false;
  138. }
  139. /**
  140. * Invoked when a search query is submitted
  141. *
  142. * @param query Selected Post object
  143. */
  144. @Override
  145. public void onSearchSubmitted(String query) {
  146. FragmentTransaction ft = fm.beginTransaction();
  147. ft.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right,
  148. android.R.anim.slide_in_left, android.R.anim.slide_out_right);
  149.  
  150. // Send query to fragment using factory method
  151. srf = SearchResultFragment.newInstance(query);
  152. ft.add(android.R.id.content, srf);
  153. ft.hide(tlf);
  154. ft.addToBackStack(null);
  155. ft.commit();
  156. }
  157.  
  158.  
  159. @Override
  160. public void onInfoSelected() {
  161.  
  162. abf = (AboutFragment) getSupportFragmentManager().findFragmentByTag(ABOUT_FRAGMENT_TAG);
  163.  
  164. FragmentTransaction ft = fm.beginTransaction();
  165. ft.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right,
  166. android.R.anim.slide_in_left, android.R.anim.slide_out_right);
  167. // ft.hide(pf);
  168.  
  169. //ft.hide(cf);
  170. ft.hide(tlf);
  171. ft.show(abf);
  172. ft.addToBackStack(null);
  173. ft.commit();
  174. }
  175. /**
  176. * Invoked when comment menu is selected
  177. *
  178. * @param id ID of the article, assigned by WordPress
  179. */
  180. @Override
  181. public void onCommentSelected(int id) {
  182. cf = (CommentFragment) getSupportFragmentManager().findFragmentByTag(COMMENT_FRAGMENT_TAG);
  183. Bundle args = new Bundle();
  184. args.putInt("id", id);
  185. // Setup CommentFragment to display the right comments page
  186. cf.setUIArguments(args);
  187.  
  188. FragmentTransaction ft = fm.beginTransaction();
  189. ft.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right,
  190. android.R.anim.slide_in_left, android.R.anim.slide_out_right);
  191. ft.hide(pf);
  192. //ft.hide(abf);
  193. ft.show(cf);
  194. ft.addToBackStack(null);
  195. ft.commit();
  196. }
  197.  
  198. /**
  199. * Intercept back button event, reset ActionBar if necessary
  200. */
  201. @Override
  202. public void onBackPressed() {
  203. resetActionBarIfApplicable();
  204. super.onBackPressed();
  205. }
  206.  
  207. /**
  208. * Simulate a back button press when home is selected
  209. */
  210. @Override
  211. public void onHomePressed() {
  212. resetActionBarIfApplicable();
  213. fm.popBackStack();
  214. }
  215.  
  216. /**
  217. * Reset TabLayoutFragment's ActionBar if necessary
  218. */
  219. private void resetActionBarIfApplicable() {
  220. Log.d(TAG, "SearchResultFragment is visible: " + srf.isHidden());
  221. if (srf.isVisible()) {
  222. tlf.resetActionBar();
  223. }
  224. }
  225.  
  226. // Commented out coz we will let fragments handle their own Options Menus
  227. /*
  228. @Override
  229. public boolean onCreateOptionsMenu(Menu menu) {
  230. // Inflate the menu; this adds items to the action bar if it is present.
  231. getMenuInflater().inflate(R.menu.menu_main, menu);
  232. //Log.e("Erroraaa","aaaaa");
  233.  
  234. return true;
  235. }
  236.  
  237.  
  238.  
  239. @Override
  240. public boolean onOptionsItemSelected(MenuItem item) {
  241.  
  242. Log.e("menu","activity: action home has clicked");
  243. switch (item.getItemId()){
  244. case android.R.id.home:
  245.  
  246. onBackPressed();
  247. return false;
  248.  
  249. }
  250.  
  251. return super.onOptionsItemSelected(item);
  252. }
  253. */
  254.  
  255. }
  256.  
  257. package me.declangao.jiasazsales.app;
  258.  
  259. import android.app.Activity;
  260.  
  261. import android.os.Bundle;
  262. import android.support.v4.app.Fragment;
  263. import android.support.v4.app.FragmentTransaction;
  264. import android.support.v7.widget.Toolbar;
  265. import android.util.Log;
  266. import android.view.LayoutInflater;
  267. import android.view.Menu;
  268. import android.view.MenuInflater;
  269. import android.view.MenuItem;
  270. import android.view.View;
  271. import android.view.ViewGroup;
  272.  
  273. import me.declangao.jiasazsales.R;
  274.  
  275. /**
  276. * Fragment to display a Info about Jiasaz company.
  277. * Activities that contain this fragment must implement the
  278. * {@link AboutFragment.AboutListener} interface
  279. * to handle interaction events.
  280. */
  281. public class AboutFragment extends Fragment {
  282.  
  283.  
  284.  
  285. private AboutListener mListener;
  286. private Toolbar toolbar;
  287.  
  288.  
  289. @Override
  290. public void onCreate(Bundle savedInstanceState) {
  291. super.onCreate(savedInstanceState);
  292. this.setRetainInstance(true);
  293.  
  294. this.setHasOptionsMenu(true);
  295.  
  296. }
  297.  
  298. // @Override
  299. // public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  300. // Log.e("Menu:created","Menu");
  301. //
  302. //// super.onCreateOptionsMenu(menu, inflater);
  303. //// menu.clear();
  304. // inflater.inflate(R.menu.menu_post, menu);
  305. // super.onCreateOptionsMenu(menu, inflater);
  306. // }
  307. @Override
  308. public boolean onOptionsItemSelected(MenuItem item) {
  309. Log.e("Menu:selected","Menu");
  310. if (item.getItemId() == android.R.id.home) {
  311. mListener.onHomePressed();
  312. }
  313. return false;
  314. }
  315.  
  316.  
  317. public AboutFragment() {
  318. // Required empty public constructor
  319. }
  320.  
  321. @Override
  322. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  323. Bundle savedInstanceState) {
  324.  
  325. // Inflate the layout for this fragment
  326. View rootView = inflater.inflate(R.layout.about_layout, container, false);
  327.  
  328. toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
  329. ((MainActivity) getActivity()).setSupportActionBar(toolbar);
  330. ((MainActivity) getActivity()).getSupportActionBar().setHomeButtonEnabled(true);
  331. ((MainActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  332. ((MainActivity) getActivity()).getSupportActionBar().setTitle( "www.Jiasaz.com");
  333. Log.e("Menu: fragment created","onCreaate()");
  334.  
  335. return rootView;
  336. }
  337.  
  338. @Override
  339. public void onAttach(Activity activity) {
  340. super.onAttach(activity);
  341. try {
  342. mListener = (AboutListener) activity;
  343. } catch (ClassCastException e) {
  344. throw new ClassCastException(activity.toString()
  345. + " must implement AboutListener");
  346. }
  347. }
  348.  
  349. @Override
  350. public void onDetach() {
  351. super.onDetach();
  352. mListener = null;
  353. }
  354.  
  355. /**
  356. * This interface must be implemented by activities that contain this
  357. * fragment to allow an interaction in this fragment to be communicated
  358. * to the activity and potentially other fragments contained in that
  359. * activity.
  360. * <p/>
  361. * See the Android Training lesson <a href=
  362. * "http://developer.android.com/training/basics/fragments/communicating.html"
  363. * >Communicating with Other Fragments</a> for more information.
  364. */
  365. public interface AboutListener {
  366. void onHomePressed();
  367. //void onInfoSelected();
  368. }
  369.  
  370.  
  371.  
  372.  
  373. }
  374.  
  375. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  376. xmlns:app="http://schemas.android.com/apk/res-auto"
  377. xmlns:tools="http://schemas.android.com/tools"
  378. android:layout_width="match_parent"
  379. android:layout_height="match_parent"
  380. android:background="@color/colorAccent"
  381. android:layoutDirection="rtl"
  382. android:textDirection="rtl"
  383.  
  384. tools:context="me.declangao.jiasazsales.app.AboutFragment">
  385.  
  386. <LinearLayout
  387. android:layout_width="match_parent"
  388. android:layout_height="match_parent"
  389. android:layoutDirection="rtl"
  390. android:textDirection="rtl"
  391. android:orientation="vertical">
  392.  
  393. <android.support.v7.widget.Toolbar
  394. android:id="@+id/toolbar"
  395. android:layout_width="match_parent"
  396. android:layout_height="?attr/actionBarSize"
  397. android:background="@color/colorPrimary"
  398. android:theme="@style/ThemeOverlay.AppCompat.Dark"
  399. android:layoutDirection="rtl"
  400. android:textDirection="rtl"
  401. />
  402.  
  403. <LinearLayout
  404. android:layout_width="match_parent"
  405. android:layout_height="match_parent"
  406. android:layoutDirection="rtl"
  407. android:textDirection="rtl"
  408. android:padding="15dp"
  409. android:orientation="vertical">
  410.  
  411. <TextView
  412. android:id="@+id/textView2"
  413. android:layout_width="match_parent"
  414. android:layout_height="wrap_content"
  415. android:layout_marginTop="20dp"
  416. android:layout_marginBottom="10dp"
  417. android:text="ئه‌م ئاپه‌ له‌لایه‌ن كۆمپانیای جیاساز دروست كراوه‌"
  418. android:textAppearance="@style/TextAppearance.AppCompat.Light.SearchResult.Title" />
  419.  
  420. <ImageView
  421. android:id="@+id/imageView"
  422. android:layout_width="match_parent"
  423. android:layout_height="214dp"
  424. android:src="@drawable/jiasazlogo" />
  425.  
  426. <TextView
  427. android:id="@+id/textView"
  428. android:layout_width="match_parent"
  429. android:layout_height="wrap_content"
  430. android:layout_marginTop="20dp"
  431. android:layout_marginBottom="10dp"
  432. android:text="كۆمپانیای جیاساز بۆ خزمه‌تگوزاری و چاره‌سه‌ری ته‌كنه‌لۆجی، دروستكردنی وێبسایت و ئاپی مۆبایل و سیسته‌می دام و ده‌زگاكان و ماركێته‌كان"
  433. android:textAppearance="@style/TextAppearance.AppCompat.Light.SearchResult.Title" />
  434.  
  435. <TextView
  436. android:id="@+id/textView3"
  437. android:layout_width="match_parent"
  438. android:layout_height="wrap_content"
  439. android:layout_gravity="center_horizontal"
  440. android:autoLink="all"
  441. android:clickable="true"
  442. android:text="@string/link"
  443. android:textAlignment="center"
  444. android:textAppearance="@style/TextAppearance.AppCompat.Body1"
  445. android:textSize="18sp" />
  446.  
  447. </LinearLayout>
  448. </LinearLayout>
  449.  
  450. </FrameLayout>
Add Comment
Please, Sign In to add comment