Guest User

Untitled

a guest
Jan 18th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.50 KB | None | 0 0
  1. import android.os.Bundle;
  2. import android.support.annotation.NonNull;
  3. import android.support.annotation.Nullable;
  4. import android.support.v4.app.Fragment;
  5. import android.support.v7.widget.LinearLayoutManager;
  6. import android.support.v7.widget.RecyclerView;
  7. import android.view.LayoutInflater;
  8. import android.view.View;
  9. import android.view.ViewGroup;
  10. import android.widget.TextView;
  11.  
  12. import com.firebase.ui.database.FirebaseRecyclerAdapter;
  13. import com.firebase.ui.database.FirebaseRecyclerOptions;
  14. import com.google.firebase.database.FirebaseDatabase;
  15. import com.google.firebase.database.Query;
  16.  
  17. /**
  18. * Created by Akib on 1/18/2018.
  19. */
  20.  
  21. public class BlogActivity extends Fragment {
  22. private RecyclerView recyclerView;
  23. private Query query;
  24. private FirebaseRecyclerAdapter firebaseRecyclerAdapter;
  25. public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
  26. View v = inflater.inflate(R.layout.activity_blog, container, false);
  27.  
  28.  
  29. return v;
  30. }
  31. public static class BlogViewHolder extends RecyclerView.ViewHolder{
  32. View view;
  33. public BlogViewHolder(View itemView) {
  34. super(itemView);
  35. view=itemView;
  36. }
  37. public void setTitle(String title)
  38. {
  39. TextView post_title=(TextView) view.findViewById(R.id.title);
  40. post_title.setText(title);
  41. }
  42. public void setDescription(String description)
  43. {
  44. TextView post_desc=(TextView) view.findViewById(R.id.description);
  45. post_desc.setText(description);
  46. }
  47. }
  48.  
  49. @Override
  50. public void onStart() {
  51. super.onStart();
  52. firebaseRecyclerAdapter.startListening();
  53. }
  54.  
  55. @Override
  56. public void onStop() {
  57. super.onStop();
  58. firebaseRecyclerAdapter.stopListening();
  59. }
  60.  
  61. public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  62. super.onViewCreated(view, savedInstanceState);
  63. recyclerView=(RecyclerView) view.findViewById(R.id.recycleview);
  64. recyclerView.setHasFixedSize(true);
  65. recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
  66. query= FirebaseDatabase.getInstance().getReference().child("Blog");
  67. FirebaseRecyclerOptions<BlogDesc> options=new FirebaseRecyclerOptions.Builder<BlogDesc>().setQuery(query,BlogDesc.class).build();
  68. firebaseRecyclerAdapter=new FirebaseRecyclerAdapter<BlogDesc, BlogViewHolder>(options) {
  69.  
  70. @Override
  71. public BlogViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  72. View view;
  73. view=LayoutInflater.from(parent.getContext()).inflate(R.layout.blog_row,parent,false);
  74. return new BlogViewHolder(view);
  75. }
  76.  
  77. @Override
  78. protected void onBindViewHolder(@NonNull BlogViewHolder holder, int position, @NonNull BlogDesc model) {
  79. holder.setTitle(model.getTitle());
  80. holder.setDescription(model.getDescription());
  81. }
  82. };
  83. recyclerView.setAdapter(firebaseRecyclerAdapter);
  84. getActivity().setTitle("Blog");
  85.  
  86. }
  87. }
  88.  
  89. import android.os.Bundle;
  90. import android.support.design.widget.FloatingActionButton;
  91. import android.support.design.widget.Snackbar;
  92. import android.support.v4.app.Fragment;
  93. import android.support.v4.app.FragmentTransaction;
  94. import android.view.View;
  95. import android.support.design.widget.NavigationView;
  96. import android.support.v4.view.GravityCompat;
  97. import android.support.v4.widget.DrawerLayout;
  98. import android.support.v7.app.ActionBarDrawerToggle;
  99. import android.support.v7.app.AppCompatActivity;
  100. import android.support.v7.widget.Toolbar;
  101. import android.view.Menu;
  102. import android.view.MenuItem;
  103.  
  104. public class HomeActivity extends AppCompatActivity
  105. implements NavigationView.OnNavigationItemSelectedListener {
  106.  
  107. @Override
  108. protected void onCreate(Bundle savedInstanceState) {
  109. super.onCreate(savedInstanceState);
  110. setContentView(R.layout.activity_home);
  111. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  112. setSupportActionBar(toolbar);
  113.  
  114.  
  115. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  116. ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
  117. this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  118. drawer.addDrawerListener(toggle);
  119. toggle.syncState();
  120.  
  121. NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  122. navigationView.setNavigationItemSelectedListener(this);
  123. }
  124.  
  125. @Override
  126. public void onBackPressed() {
  127. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  128. if (drawer.isDrawerOpen(GravityCompat.START)) {
  129. drawer.closeDrawer(GravityCompat.START);
  130. } else {
  131. super.onBackPressed();
  132. }
  133. }
  134.  
  135. @Override
  136. public boolean onCreateOptionsMenu(Menu menu) {
  137. // Inflate the menu; this adds items to the action bar if it is present.
  138. getMenuInflater().inflate(R.menu.home, menu);
  139. return true;
  140. }
  141.  
  142. @Override
  143. public boolean onOptionsItemSelected(MenuItem item) {
  144. // Handle action bar item clicks here. The action bar will
  145. // automatically handle clicks on the Home/Up button, so long
  146. // as you specify a parent activity in AndroidManifest.xml.
  147. int id = item.getItemId();
  148.  
  149. //noinspection SimplifiableIfStatement
  150. if (id == R.id.action_settings) {
  151. return true;
  152. }
  153.  
  154. return super.onOptionsItemSelected(item);
  155. }
  156. private void displaySelectedScreen(int id)
  157. {
  158. Fragment fragment =null;
  159. if (id == R.id.nav_camera) {
  160. fragment=new BlogActivity();
  161. // Handle the camera action
  162. } else if (id == R.id.nav_gallery) {
  163.  
  164. } else if (id == R.id.nav_slideshow) {
  165.  
  166. } else if (id == R.id.nav_manage) {
  167.  
  168. } else if (id == R.id.nav_share) {
  169.  
  170. } else if (id == R.id.nav_send) {
  171.  
  172. }
  173. if(fragment!=null)
  174. {
  175. FragmentTransaction fragmentTransaction=getSupportFragmentManager().beginTransaction();
  176. fragmentTransaction.replace(R.id.home_content,fragment);
  177. fragmentTransaction.commit();
  178. }
  179. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  180. drawer.closeDrawer(GravityCompat.START);
  181. }
  182. @SuppressWarnings("StatementWithEmptyBody")
  183. @Override
  184. public boolean onNavigationItemSelected(MenuItem item) {
  185. // Handle navigation view item clicks here.
  186. int id = item.getItemId();
  187.  
  188. /*if (id == R.id.nav_camera) {
  189.  
  190. // Handle the camera action
  191. } else if (id == R.id.nav_gallery) {
  192.  
  193. } else if (id == R.id.nav_slideshow) {
  194.  
  195. } else if (id == R.id.nav_manage) {
  196.  
  197. } else if (id == R.id.nav_share) {
  198.  
  199. } else if (id == R.id.nav_send) {
  200.  
  201. }
  202.  
  203. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  204. drawer.closeDrawer(GravityCompat.START);*/
  205. displaySelectedScreen(id);
  206. return true;
  207. }
  208. }
  209.  
  210. <?xml version="1.0" encoding="utf-8"?>
  211. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  212. android:orientation="vertical" android:layout_width="match_parent"
  213. android:layout_height="match_parent">
  214. <android.support.v7.widget.RecyclerView
  215. android:id="@+id/recycleview"
  216. android:layout_width="match_parent"
  217. android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>
  218. </LinearLayout>
  219.  
  220. <?xml version="1.0" encoding="utf-8"?>
  221. <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
  222. android:layout_width="match_parent" android:layout_height="match_parent">
  223. <LinearLayout
  224. android:layout_width="match_parent"
  225. android:layout_height="wrap_content"
  226. android:orientation="vertical">
  227.  
  228. <TextView
  229. android:layout_width="match_parent"
  230. android:layout_height="wrap_content"
  231. android:id="@+id/title"/>
  232. <TextView
  233. android:layout_width="match_parent"
  234. android:layout_height="wrap_content"
  235. android:id="@+id/description"/>
  236. </LinearLayout>
  237. </android.support.v7.widget.CardView>
  238.  
  239. 01-19 03:44:05.396 23502-23502/com.aust.austpc.austpcportalbeta4 E/AndroidRuntime: FATAL EXCEPTION: main
  240. Process: com.aust.austpc.austpcportalbeta4, PID: 23502
  241. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aust.austpc.austpcportalbeta4/com.aust.austpc.austpcportalbeta4.HomeActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.design.widget.NavigationView
  242. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2455)
  243. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2515)
  244. at android.app.ActivityThread.access$1000(ActivityThread.java:154)
  245. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1379)
  246. at android.os.Handler.dispatchMessage(Handler.java:102)
  247. at android.os.Looper.loop(Looper.java:157)
  248. at android.app.ActivityThread.main(ActivityThread.java:5571)
  249. at java.lang.reflect.Method.invoke(Native Method)
  250. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745)
  251. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)
  252. Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.design.widget.NavigationView
  253. at android.view.LayoutInflater.inflate(LayoutInflater.java:543)
  254. at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
  255. at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
  256. at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
  257. at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
  258. at com.aust.austpc.austpcportalbeta4.HomeActivity.onCreate(HomeActivity.java:24)
  259. at android.app.Activity.performCreate(Activity.java:6357)
  260. at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
  261. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408)
  262. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2515) 
  263. at android.app.ActivityThread.access$1000(ActivityThread.java:154) 
  264. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1379) 
  265. at android.os.Handler.dispatchMessage(Handler.java:102) 
  266. at android.os.Looper.loop(Looper.java:157) 
  267. at android.app.ActivityThread.main(ActivityThread.java:5571) 
  268. at java.lang.reflect.Method.invoke(Native Method) 
  269. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745) 
  270. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635) 
  271. Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.support.design.widget.NavigationView
  272. at android.view.LayoutInflater.createView(LayoutInflater.java:649)
  273. at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:768)
  274. at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708)
  275. at android.view.LayoutInflater.rInflate(LayoutInflater.java:839)
  276. at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
  277. at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
  278. at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
  279. at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
  280. at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
  281. at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
  282. at com.aust.austpc.austpcportalbeta4.HomeActivity.onCreate(HomeActivity.java:24) 
  283. at android.app.Activity.performCreate(Activity.java:6357) 
  284. at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
  285. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408) 
  286. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2515) 
  287. at android.app.ActivityThread.access$1000(ActivityThread.java:154) 
  288. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1379) 
  289. at android.os.Handler.dispatchMessage(Handler.java:102) 
  290. at android.os.Looper.loop(Looper.java:157) 
  291. at android.app.ActivityThread.main(ActivityThread.java:5571) 
  292. at java.lang.reflect.Method.invoke(Native Method) 
  293. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745) 
  294. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635) 
  295. Caused by: java.lang.reflect.InvocationTargetException
  296. at java.lang.reflect.Constructor.newInstance(Native Method)
  297. at android.view.LayoutInflater.createView(LayoutInflater.java:623)
  298. at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:768) 
  299. at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708) 
  300. at android.view.LayoutInflater.rInflate(LayoutInflater.java:839) 
  301. at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802) 
  302. at android.view.LayoutInflater.inflate(LayoutInflater.java:519) 
  303. at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
  304. at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
  305. at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
  306. at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
  307. at com.aust.austpc.austpcportalbeta4.HomeActivity.onCreate(HomeActivity.java:24) 
  308. at android.app.Activity.performCreate(Activity.java:6357) 
  309. at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
  310. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408) 
  311. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2515) 
  312. at android.app.ActivityThread.access$1000(ActivityThread.java:154) 
  313. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1379) 
  314. at android.os.Handler.dispatchMessage(Handler.java:102) 
  315. at android.os.Looper.loop(Looper.java:157) 
  316. at android.app.ActivityThread.main(ActivityThread.java:5571) 
  317. at java.lang.reflect.Method.invoke(Native Method) 
  318. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745) 
  319. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635) 
  320. Caused by: java.lang.NoSuchMethodError: No static method getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)Landroid/graphics/Typeface; in class Landroid/support/v4/content/res/ResourcesCompat; or its super classes (declaration of 'android.support.v4.content.res.ResourcesCompat' appears in /data/app/com.aust.austpc.austpcportalbeta4-1/split_lib_dependencies_apk.apk)
  321. at android.support.v7.widget.TintTypedArray.getFont(TintTypedArray.java:119)
  322. at android.support.v7.widget.AppCompatTextHelper.updateTypefaceAndStyle(AppCompatTextHelper.java:208)
  323. at android.support.v7.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:110)
  324. at android.support.v7.widget.AppCompatTextHelperV17.loadFromAttributes(AppCompatTextHelperV17.java:38)
  325. at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:81)
  326. at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:71)
  327. at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
  328. at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024)
  329. at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081)
  330. at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
  331. at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708)
  332. at android.
  333. 01-19 03:44:35.077 23502-23581/com.aust.austpc.austpcportalbeta4 E/FirebaseInstanceId: Token retrieval failed: TIMEOUT
Add Comment
Please, Sign In to add comment