Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.imaadv.leaynik.Activities;
- /*
- * Copyright (C) 2014 Chris Renke
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- import android.app.AlertDialog;
- import android.app.Dialog;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.res.Resources;
- import android.content.res.TypedArray;
- import android.net.Uri;
- import android.os.Bundle;
- import android.support.v4.app.ActivityCompat;
- import android.support.v4.app.Fragment;
- import android.support.v4.app.FragmentActivity;
- import android.support.v4.app.FragmentManager;
- import android.support.v4.widget.DrawerLayout;
- import android.view.Gravity;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.AdapterView;
- import android.widget.AdapterView.OnItemClickListener;
- import android.widget.Button;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.ListView;
- import android.widget.TextView;
- import com.imaadv.leaynik.R;
- import com.imaadv.leaynik.api.API;
- import com.imaadv.leaynik.defs.AppConstants;
- import com.imaadv.leaynik.defs.DrawerItem;
- import com.imaadv.leaynik.test.Test_Home;
- import com.imaadv.leaynik.ui.DrawerAdapter;
- import java.util.ArrayList;
- public class Home extends FragmentActivity {
- private final static int DAYS_UNTIL_PROMPT = 3;
- private final static int LAUNCHES_UNTIL_PROMPT = 7;
- private DrawerArrowDrawable drawerArrowDrawable;
- private float offset;
- private boolean flipped;
- private ListView DrawerList;
- private DrawerLayout drawer;
- private TextView styleButton;
- private API api;
- private String[] nav_items;
- private TypedArray nav_icons;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // requestWindowFeature(Window.FEATURE_NO_TITLE);
- // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- // WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.home_view);
- api = new API(this);
- if (!api.getSetting(AppConstants.ALERT).contentEquals(AppConstants.TRUE))
- openAlert();
- DrawerList = (ListView) findViewById(R.id.DrawerList);
- ArrayList<DrawerItem> Items = new ArrayList<DrawerItem>(9);
- Resources res= getResources();
- nav_items = res.getStringArray(R.array.nav_items);
- nav_icons = res.obtainTypedArray(R.array.nav_icon);
- for(int i=0 ; i<nav_items.length ; i++){
- Items.add(new DrawerItem(nav_items[i] , nav_icons.getResourceId(i,-1)));
- }
- // Items.add(new DrawerItem(getResources().getString(R.string.tests),
- // R.drawable.test));
- // Items.add(new DrawerItem(getResources().getString(R.string.disease),
- // R.drawable.ill));
- // Items.add(new DrawerItem(getResources().getString(R.string.questions),
- // R.drawable.questions));
- // Items.add(new DrawerItem(getResources().getString(R.string.clincs),
- // R.drawable.location));
- // Items.add(new DrawerItem(getResources().getString(R.string.medtime),
- // R.drawable.alram));
- // Items.add(new DrawerItem(getResources().getString(R.string.articales),
- // R.drawable.articles));
- // Items.add(new DrawerItem(getResources().getString(R.string.profile),
- // R.drawable.profile));
- // Items.add(new DrawerItem(getResources().getString(R.string.compition),
- // R.drawable.quiz));
- //
- // Items.add(new DrawerItem(getResources().getString(R.string.logout),
- // R.drawable.logout));
- DrawerAdapter adapter = new DrawerAdapter(this, Items);
- DrawerList.setAdapter(adapter);
- DrawerList.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
- long arg3) {
- SelectItem(arg2);
- }
- });
- drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
- final ImageView imageView = (ImageView) findViewById(R.id.drawer_indicator);
- final Resources resources = getResources();
- drawerArrowDrawable = new DrawerArrowDrawable(resources);
- drawerArrowDrawable.setStrokeColor(resources
- .getColor(R.color.light_gray));
- imageView.setImageDrawable(drawerArrowDrawable);
- drawer.setDrawerListener(new DrawerLayout.SimpleDrawerListener() {
- @Override
- public void onDrawerSlide(View drawerView, float slideOffset) {
- offset = slideOffset;
- // Sometimes slideOffset ends up so close to but not quite 1 or
- // 0.
- if (slideOffset >= .995) {
- flipped = true;
- drawerArrowDrawable.setFlip(flipped);
- } else if (slideOffset <= .005) {
- flipped = false;
- drawerArrowDrawable.setFlip(flipped);
- }
- drawerArrowDrawable.setParameter(offset);
- }
- });
- openDrawer();
- imageView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // if (drawer.isDrawerVisible(5)) {
- // drawer.closeDrawer(5);
- // } else {
- // drawer.openDrawer(5);
- // }
- openDrawer();
- }
- });
- styleButton = (TextView) findViewById(R.id.indicator_style);
- FragmentManager fragmentManager = getSupportFragmentManager();
- int commit = fragmentManager
- .beginTransaction()
- .replace(R.id.view_content, Test_Home.newInstance(), "FRAGMENT")
- .addToBackStack(null).commit();
- DrawerList.setItemChecked(0, true);
- // drawer.closeDrawer(5);
- int numberofentrance = Integer.parseInt(api.getSetting("launch_count")) + 1;
- api.setSetting("launch_count", String.valueOf(numberofentrance));
- Long date_firstLaunch = Long.parseLong(api
- .getSetting("date_firstlaunch"));
- if (date_firstLaunch == 0) {
- date_firstLaunch = System.currentTimeMillis();
- api.setSetting("date_firstlaunch", String.valueOf(date_firstLaunch));
- }
- if (numberofentrance >= LAUNCHES_UNTIL_PROMPT) {
- if (System.currentTimeMillis() >= date_firstLaunch
- + (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
- showRateDialog();
- }
- }
- }
- public void showRateDialog() {
- final Dialog dialog = new Dialog(this);
- dialog.setTitle("Rate " + getResources().getString(R.string.app_name));
- LinearLayout ll = new LinearLayout(this);
- ll.setOrientation(LinearLayout.VERTICAL);
- TextView tv = new TextView(this);
- tv.setText("If you enjoy using "
- + getResources().getString(R.string.app_name)
- + ", please take a moment to rate it. Thanks for your support!");
- tv.setWidth(240);
- tv.setPadding(4, 0, 4, 10);
- ll.addView(tv);
- Button b1 = new Button(this);
- b1.setText("Rate " + getResources().getString(R.string.app_name));
- b1.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- startActivity(new Intent(Intent.ACTION_VIEW, Uri
- .parse("market://details?id=" + "com.imaadv.leaynik")));
- dialog.dismiss();
- }
- });
- ll.addView(b1);
- Button b2 = new Button(this);
- b2.setText("Remind me later");
- b2.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- dialog.dismiss();
- }
- });
- ll.addView(b2);
- Button b3 = new Button(this);
- b3.setText("No, thanks");
- b3.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- api.setSetting(AppConstants.DONTSHOWAGAIN, AppConstants.TRUE);
- dialog.dismiss();
- }
- });
- ll.addView(b3);
- dialog.setContentView(ll);
- dialog.show();
- }
- private void openDrawer() {
- if (drawer.isDrawerVisible(Gravity.RIGHT)) {
- drawer.closeDrawer(Gravity.RIGHT);
- } else {
- drawer.openDrawer(Gravity.RIGHT);
- }
- }
- @Override
- public void onBackPressed() {
- FragmentManager manager = getSupportFragmentManager();
- int count = manager.getBackStackEntryCount();
- Test_Home fragement = (Test_Home) getSupportFragmentManager()
- .findFragmentByTag("FRAGMENT");
- if (count == 0) {
- // if (fragement != null)
- if (fragement.isVisible()) {
- // super.onBackPressed();
- Home.this.finish();
- // System.exit(0);
- } else {
- // super.onBackPressed();
- }
- } else {
- if (api.getSetting("zft").contentEquals("zft")) {
- api.setSetting("zft", "");
- // Home.this.finish();
- ActivityCompat.finishAffinity(this);
- } else
- manager.popBackStack();
- //
- }
- styleButton.setText(getResources().getString(R.string.app_name));
- }
- private void openAlert() {
- api.setSetting(AppConstants.ALERT, AppConstants.TRUE);
- AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
- Home.this);
- alertDialogBuilder
- .setTitle(getResources().getString(R.string.app_name));
- alertDialogBuilder.setMessage(getResources().getString(R.string.sos));
- // set positive button: Yes message
- alertDialogBuilder.setPositiveButton(
- getResources().getString(R.string.ok),
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- }
- });
- AlertDialog alertDialog = alertDialogBuilder.create();
- // show alert
- alertDialog.show();
- }
- private void Logout() {
- AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
- Home.this);
- alertDialogBuilder
- .setTitle(getResources().getString(R.string.app_name));
- alertDialogBuilder.setMessage(getResources().getString(
- R.string.logout_msg));
- // set positive button: Yes message
- alertDialogBuilder.setPositiveButton(
- getResources().getString(R.string.ok),
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- if (api == null) {
- api = new API(Home.this);
- }
- api.clearSettings();
- finish();
- }
- });
- alertDialogBuilder.setNegativeButton(
- getResources().getString(R.string.cancel),
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface arg0, int arg1) {
- }
- });
- AlertDialog alertDialog = alertDialogBuilder.create();
- // show alert
- alertDialog.show();
- }
- public void SelectItem(int position) {
- FragmentManager fragmentManager = getSupportFragmentManager();
- Fragment fragment = new Fragment();
- int commit = 0;
- switch (position) {
- case 0:
- styleButton.setText(getResources().getString(R.string.tests));
- commit = fragmentManager
- .beginTransaction()
- .replace(R.id.view_content, Test_Home.newInstance(),
- "FRAGMENT").addToBackStack(null).commit();
- api.setSetting("name", getResources().getString(R.string.tests));
- break;
- case 1:
- styleButton.setText(getResources().getString(R.string.disease));
- commit = fragmentManager.beginTransaction()
- .replace(R.id.view_content, Diases_Fragment.newInstance())
- .addToBackStack("tag").commit();
- api.setSetting("name", getResources().getString(R.string.disease));
- break;
- case 2:
- styleButton.setText(getResources().getString(R.string.questions));
- commit = fragmentManager
- .beginTransaction()
- .replace(R.id.view_content,
- Questions_Fragment.newInstance())
- .addToBackStack("tag").commit();
- api.setSetting("name", getResources().getString(R.string.questions));
- break;
- case 3:
- styleButton.setText(getResources().getString(R.string.clincs));
- commit = fragmentManager.beginTransaction()
- .replace(R.id.view_content, Clinc_Fragment.newInstance())
- .addToBackStack("tag").commit();
- api.setSetting("name", getResources().getString(R.string.clincs));
- break;
- case 4:
- styleButton.setText(getResources().getString(R.string.medtime));
- commit = fragmentManager
- .beginTransaction()
- .replace(R.id.view_content, Reminder_Fragment.newInstance())
- .addToBackStack("tag").commit();
- api.setSetting("name", getResources().getString(R.string.medtime));
- break;
- case 5:
- styleButton.setText(getResources().getString(R.string.articales));
- commit = fragmentManager
- .beginTransaction()
- .replace(R.id.view_content, ArticalesFragment.newInstance())
- .addToBackStack("tag").commit();
- api.setSetting("name", getResources().getString(R.string.articales));
- break;
- case 6:
- styleButton.setText(getResources().getString(R.string.profile));
- commit = fragmentManager.beginTransaction()
- .replace(R.id.view_content, Profile_Fragment.newInstance())
- .addToBackStack("tag").commit();
- api.setSetting("name", getResources().getString(R.string.profile));
- break;
- case 7:
- styleButton.setText(getResources().getString(R.string.compition));
- commit = fragmentManager
- .beginTransaction()
- .replace(R.id.view_content,
- Competion_Fragment.newInstance())
- .addToBackStack("tag").commit();
- api.setSetting("name", getResources().getString(R.string.compition));
- break;
- case 8:
- Logout();
- break;
- }
- DrawerList.setItemChecked(position, true);
- // setTitle(dataList.get(position).getItemName());
- drawer.closeDrawer(Gravity.RIGHT);
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- }
- public void replaceTestFragment(Test_Home fragment) {
- styleButton.setText(getResources().getString(R.string.tests));
- FragmentManager fragmentManager = getSupportFragmentManager();
- fragmentManager.beginTransaction()
- .replace(R.id.view_content, fragment.newInstance())
- .addToBackStack("tag").commit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement