Example usage for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

Introduction

In this page you can find the example usage for android.content Intent FLAG_ACTIVITY_CLEAR_TOP.

Prototype

int FLAG_ACTIVITY_CLEAR_TOP

To view the source code for android.content Intent FLAG_ACTIVITY_CLEAR_TOP.

Click Source Link

Document

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

Usage

From source file:com.example.android.rowanparkingpass.Activities.PassActivity.java

@Override
public void onClick(View view) {
    Intent intent;// w  w  w. j a va  2s.co m
    if (view == startDate) {
        // Select Pass Start Date using a date selector
        startDatePickerDialog.show();
    } else if (view == endDate) {
        // Select Pass End Date using a date selector
        endDatePickerDialog.show();
    } else {
        if (view == createPass) {
            //TODO Temp driver created the pass is still created with null null null
            if (NetworkCheck.haveNetworkConnection()) {
                new SendToServer().send();

                executeProcessRequest();
            } else {
                Toast.makeText(getApplicationContext(), "No Network Connection. Cannot create a pass.s",
                        Toast.LENGTH_LONG).show();
            }
        } else if (view == mainMenu) {
            // Goes back to main menu
            intent = new Intent(getApplicationContext(), PassesActivity.class);
            intent.putExtra(MODE, mode.HOME_PAGE.name());
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            finish();
        }
    }
}

From source file:com.android.yijiang.kzx.http.AsyncHttpResponseHandler.java

final public void sendSuccessMessage(int statusCode, Header[] headers, byte[] responseBytes) {
    String content = new String(responseBytes);
    if (content.indexOf("invalid key") != -1 || content.indexOf("token missing") != -1) {
        if (ApplicationController.mCount > 0) {
            return;
        }//from   www.  j  a  va2s.  c  o m
        new Thread(new Runnable() {
            @Override
            public void run() {
                Looper.prepare();
                ApplicationController.mCount++;
                MsgTools.toast(ApplicationController.getInstance(), "?,?!",
                        Toast.LENGTH_LONG);
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        gotoLogin();
                    }
                }, Toast.LENGTH_SHORT);
                ApplicationController.mCount = 0;
                Looper.loop();
            }
        }).run();
    } else if (content.indexOf("need team") != -1) {
        Intent i = new Intent(ApplicationController.getInstance(), ContentFragmentActivity.class);
        i.putExtra("action", "create_team");
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        ApplicationController.getInstance().startActivity(i);
    } else {
        try {
            final boolean success = new JSONObject(content).optBoolean("success", false);
            final String message = new JSONObject(content).optString("message");
            final String data = new JSONObject(content).optString("data");
            if (!success && "null".equals(data) && StringUtils.isEmpty(message)) {
                gotoLogin();
                return;
            } else if (!success && "null".equals(data) && !StringUtils.isEmpty(message)) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        Looper.prepare();
                        MsgTools.toast(ApplicationController.getInstance(), message, Toast.LENGTH_LONG);
                        sendFinishMessage();
                        Looper.loop();
                    }
                }).run();
                return;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            sendMessage(obtainMessage(SUCCESS_MESSAGE, new Object[] { statusCode, headers, responseBytes }));
        }
        sendMessage(obtainMessage(SUCCESS_MESSAGE, new Object[] { statusCode, headers, responseBytes }));
    }
}

From source file:com.airbop.client.GCMIntentService.java

private static void generateImageNotification(Context context, String title, String message, String url,
        String image_url, String large_icon) {

    // The bitmap to download
    Bitmap message_bitmap = null;/*from  w  ww .  j a  v a  2  s .com*/
    // Should we download the image?
    if ((image_url != null) && (!image_url.equals(""))) {
        message_bitmap = AirBopImageDownloader.downloadBitmap(image_url);
    }
    // If we didn't get the image, we're out of here
    if (message_bitmap == null) {
        generateNotification(context, title, message, url, large_icon);
        return;
    }

    int icon = R.drawable.ic_stat_gcm;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    if ((title == null) || (title.equals(""))) {
        title = context.getString(R.string.app_name);
    }

    Intent notificationIntent = null;
    if ((url == null) || (url.equals(""))) {
        //just bring up the app
        notificationIntent = new Intent(context, DemoActivity.class);
    } else {
        //Launch the URL
        notificationIntent = new Intent(Intent.ACTION_VIEW);
        notificationIntent.setData(Uri.parse(url));
        notificationIntent.addCategory(Intent.CATEGORY_BROWSABLE);
    }

    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    Notification notification = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(message).setContentIntent(intent).setSmallIcon(icon)
            .setLargeIcon(decodeImage(large_icon)).setWhen(when)
            .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(message_bitmap)).build();

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
}

From source file:com.markupartist.sthlmtraveling.RouteDetailActivity.java

@Override
public boolean onSearchRequested() {
    Intent i = new Intent(this, StartActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(i);/*from www. j  a v  a2  s  .c  o m*/
    return true;
}

From source file:com.loadsensing.app.ImatgeXarxaSensors.java

public void goHome(Context context) {
    final Intent intent = new Intent(context, HomeActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    context.startActivity(intent);/*from   w w  w  .jav  a  2s  . c  o m*/
}

From source file:com.android.inputmethod.latin.settings.CustomInputStyleSettingsFragment.java

private AlertDialog createDialog() {
    final String imeId = mRichImm.getInputMethodIdOfThisIme();
    final AlertDialog.Builder builder = new AlertDialog.Builder(
            DialogUtils.getPlatformDialogThemeContext(getActivity()));
    builder.setTitle(R.string.custom_input_styles_title).setMessage(R.string.custom_input_style_note_message)
            .setNegativeButton(R.string.not_now, null)
            .setPositiveButton(R.string.enable, new DialogInterface.OnClickListener() {
                @Override// w w w  .ja va  2 s  .co  m
                public void onClick(DialogInterface dialog, int which) {
                    final Intent intent = IntentUtils.getInputLanguageSelectionIntent(imeId,
                            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
                                    | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    // TODO: Add newly adding subtype to extra value of the intent as a hint
                    // for the input language selection activity.
                    // intent.putExtra("newlyAddedSubtype", subtypePref.getSubtype());
                    startActivity(intent);
                }
            });

    return builder.create();
}

From source file:abanoubm.dayra.main.Main.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    if (Utility.getArabicLang(getApplicationContext()) == 1) {
        Utility.setArabicLang(getApplicationContext(), 2);

        Locale myLocale = new Locale("ar");
        Resources res = getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
        Configuration conf = res.getConfiguration();
        conf.locale = myLocale;/*from  w ww  .j  a  v  a  2 s  .  c  om*/
        res.updateConfiguration(conf, dm);

        finish();
        startActivity(new Intent(getIntent()));
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.act_main);
    ((TextView) findViewById(R.id.subhead1)).setText(R.string.app_name);
    ((TextView) findViewById(R.id.subhead2)).setText(BuildConfig.VERSION_NAME);
    findViewById(R.id.nav_back).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();

        }
    });
    ((TextView) findViewById(R.id.footer)).setText("dayra " + BuildConfig.VERSION_NAME + " @"
            + new SimpleDateFormat("yyyy", Locale.getDefault()).format(new Date()) + " Abanoub M.");

    if (!Utility.getDayraName(getApplicationContext()).equals("")) {
        startActivity(new Intent(getApplicationContext(), Home.class));
        finish();
    }

    ListView lv = (ListView) findViewById(R.id.home_list);

    mMenuItemAdapter = new MenuItemAdapter(getApplicationContext(),
            new ArrayList<>(Arrays.asList(getResources().getStringArray(R.array.sign_menu))), 1);
    lv.setAdapter(mMenuItemAdapter);

    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case 0:
                sign();
                break;
            case 1:
                register();
                break;
            case 2:
                if (Build.VERSION.SDK_INT < 23 || ContextCompat.checkSelfPermission(Main.this,
                        Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                    importDB();
                } else {
                    ActivityCompat.requestPermissions(Main.this,
                            new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE }, IMPORT_REQUEST);
                }
                break;
            case 3:
                startActivity(new Intent(Intent.ACTION_VIEW).setData(
                        Uri.parse("https://drive.google.com/file/d/0B1rNCm5K9cvwVXJTTzNqSFdrVk0/view")));
                break;
            case 4:
                startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(
                        "https://drive.google.com/open?id=1flSRdoiIT_hNd96Kxz3Ww3EhXDLZ45FhwFJ2hF9vl7g")));
                break;
            case 5: {

                AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
                builder.setTitle(R.string.label_choose_language);
                builder.setItems(getResources().getStringArray(R.array.language_menu),
                        new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                String temp;
                                if (which == 1) {
                                    temp = "en";
                                    Utility.setArabicLang(getApplicationContext(), 0);
                                } else {
                                    temp = "ar";
                                    Utility.setArabicLang(getApplicationContext(), 2);
                                }
                                Locale myLocale = new Locale(temp);
                                Resources res = getResources();
                                DisplayMetrics dm = res.getDisplayMetrics();
                                Configuration conf = res.getConfiguration();
                                conf.locale = myLocale;
                                res.updateConfiguration(conf, dm);

                                finish();
                                startActivity(new Intent(getIntent()));
                            }

                        });
                builder.create().show();

            }
                break;
            case 6:
                try {
                    getPackageManager().getPackageInfo("com.facebook.katana", 0);
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/453595434816965"))
                            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
                } catch (Exception e) {
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/dayraapp"))
                            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
                }
                break;

            case 7:

                try {
                    getPackageManager().getPackageInfo("com.facebook.katana", 0);
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/1363784786"))
                            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
                } catch (Exception e) {
                    startActivity(
                            new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/EngineeroBono"))
                                    .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
                }
                break;
            case 8:
                Uri uri = Uri.parse("market://details?id=" + getPackageName());
                Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
                try {
                    startActivity(goToMarket);
                } catch (Exception e) {
                    startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
                }
                break;
            case 9:
                if (Build.VERSION.SDK_INT < 23 || ContextCompat.checkSelfPermission(Main.this,
                        android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                    Intent intent = new Intent(Intent.ACTION_VIEW).addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                    intent.setDataAndType(Uri.fromFile(new File(Utility.getDayraFolder())), "*/*");
                    startActivity(
                            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
                } else {
                    ActivityCompat.requestPermissions(Main.this,
                            new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE },
                            FOLDER_REQUEST);
                }
                break;
            case 10:
                LayoutInflater li = LayoutInflater.from(getApplicationContext());
                final View aboutView = li.inflate(R.layout.dialogue_about, null, false);
                final AlertDialog ad = new AlertDialog.Builder(Main.this).setCancelable(true).create();
                ad.setView(aboutView, 0, 0, 0, 0);
                ad.show();
                ((TextView) aboutView.findViewById(R.id.about))
                        .setText(String.format(getResources().getString(R.string.copyright),
                                Calendar.getInstance().get(Calendar.YEAR)));

                ((TextView) aboutView.findViewById(R.id.notice)).setText(GoogleApiAvailability.getInstance()
                        .getOpenSourceSoftwareLicenseInfo(getApplicationContext()));
                aboutView.findViewById(R.id.btn).setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        ad.cancel();
                    }
                });
                break;
            }
        }
    });

}

From source file:com.example.carsharing.LongWayActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    photouri = Uri/*w w w. j  a  va2  s . c  om*/
            .fromFile(new File(this.getExternalFilesDir(Environment.DIRECTORY_PICTURES), IMAGE_FILE_NAME2));
    System.out.println("abc");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_long_way);

    activity_drawer = new Drawer(this, R.id.long_way_layout);
    mDrawerToggle = activity_drawer.newdrawer();
    mDrawerLayout = activity_drawer.setDrawerLayout();

    // 
    standard_date = new SimpleDateFormat("yyyy-MM-dd", Locale.SIMPLIFIED_CHINESE);
    primary_date = new SimpleDateFormat("yyyyMMdd", Locale.SIMPLIFIED_CHINESE);

    queue = Volley.newRequestQueue(this);
    exchange = (ImageView) findViewById(R.id.longway_exchange);
    exchange.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            String temp = startplace.getText().toString();

            startplace.setText(endplace.getText().toString());
            endplace.setText(temp);

        }
    });

    bdriver = true;

    datebutton = (Button) findViewById(R.id.longway_dates);
    increase = (Button) findViewById(R.id.longway_increase);
    decrease = (Button) findViewById(R.id.longway_decrease);
    s1 = (TextView) findViewById(R.id.longway_count);
    sure = (Button) findViewById(R.id.longway_sure);
    sure.setEnabled(false);
    startplace = (EditText) findViewById(R.id.longway_start_place);
    endplace = (EditText) findViewById(R.id.longway_end_place);
    noteinfo = (EditText) findViewById(R.id.longway_remarkText);
    commute = findViewById(R.id.drawer_commute);
    shortway = findViewById(R.id.drawer_shortway);
    longway = findViewById(R.id.drawer_longway);
    drawericon = (ImageView) findViewById(R.id.drawer_icon);
    drawername = (TextView) findViewById(R.id.drawer_name);
    drawernum = (TextView) findViewById(R.id.drawer_phone);
    carbrand = (EditText) findViewById(R.id.longway_CarBrand);
    model = (EditText) findViewById(R.id.longway_CarModel);
    color = (EditText) findViewById(R.id.longway_color);
    setting = findViewById(R.id.drawer_setting);
    licensenum = (EditText) findViewById(R.id.longway_Num);

    licensenum.addTextChangedListener(numTextWatcher);
    carbrand.addTextChangedListener(detTextWatcher);
    color.addTextChangedListener(coTextWatcher);
    model.addTextChangedListener(moTextWatcher);
    startplace.addTextChangedListener(spTextWatcher);
    endplace.addTextChangedListener(epTextWatcher);

    final TextView content = (TextView) findViewById(R.id.longway_content);
    longway_group = (RadioGroup) findViewById(R.id.longway_radiobutton);
    passangerRadioButton = (RadioButton) findViewById(R.id.longway_radioButton02);
    driverRadioButton = (RadioButton) findViewById(R.id.longway_radioButton01);
    personalcenter = findViewById(R.id.drawer_personalcenter);
    taxi = findViewById(R.id.drawer_taxi);

    // judge the value of "pre_page"
    Bundle bundle = this.getIntent().getExtras();
    String PRE_PAGE = bundle.getString("pre_page");
    if (PRE_PAGE.compareTo("ReOrder") == 0) { // 
        startplace.setText(bundle.getString("stpmapname"));
        bstart = true;
        endplace.setText(bundle.getString("epmapname"));
        bend = true;
        datebutton.setText(bundle.getString("re_longway_startdate"));
        bdate = true;
    }
    // judge the value of "pre_page"

    // 
    SharedPreferences sharedPref = this.getSharedPreferences(getString(R.string.PreferenceDefaultName),
            Context.MODE_PRIVATE);
    UserPhoneNumber = sharedPref.getString(getString(R.string.PreferenceUserPhoneNumber), "0");

    // database
    db = new DatabaseHelper(getApplicationContext(), UserPhoneNumber, null, 1);
    db1 = db.getWritableDatabase();
    about = findViewById(R.id.drawer_respond);
    about.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent about = new Intent(LongWayActivity.this, AboutActivity.class);
            startActivity(about);
        }
    });
    setting.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent setting = new Intent(LongWayActivity.this, SettingActivity.class);
            startActivity(setting);
        }
    });

    // database end

    taxi.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
        }
    });

    personalcenter.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent personalcenter = new Intent(LongWayActivity.this, PersonalCenterActivity.class);
            personalcenter.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(personalcenter);
        }
    });

    // RadioGroup

    longway_group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup arg0, int checkedId) {
            // TODO Auto-generated method stub18
            // ID

            // """"textView
            if (checkedId == passangerRadioButton.getId()) {
                bpassenager = true;
                bdriver = false;

                licensenum.setEnabled(false);
                carbrand.setEnabled(false);
                color.setEnabled(false);
                model.setEnabled(false);

                licensenum.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
                    }
                } });
                carbrand.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
                    }
                } });
                color.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
                    }
                } });
                model.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
                    }
                } });
                content.setText(getString(R.string.warningInfo_seatNeed));
                licensenum.setHintTextColor(Color.parseColor("#cccccc"));
                carbrand.setHintTextColor(Color.parseColor("#cccccc"));
                color.setHintTextColor(Color.parseColor("#cccccc"));
                model.setHintTextColor(Color.parseColor("#cccccc"));
                licensenum.setInputType(InputType.TYPE_NULL);
                carbrand.setInputType(InputType.TYPE_NULL);
                color.setInputType(InputType.TYPE_NULL);
                model.setInputType(InputType.TYPE_NULL);
            } else {
                bpassenager = false;
                bdriver = true;

                licensenum.setEnabled(true);
                carbrand.setEnabled(true);
                color.setEnabled(true);
                model.setEnabled(true);

                licensenum.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {

                        return null;
                    }
                } });
                carbrand.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return null;
                    }
                } });
                color.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {

                        return null;
                    }
                } });
                model.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {

                        return null;
                    }
                } });
                content.setText(getString(R.string.warningInfo_seatOffer));
                licensenum.setHintTextColor(Color.parseColor("#9F35FF"));
                carbrand.setHintTextColor(Color.parseColor("#9F35FF"));
                color.setHintTextColor(Color.parseColor("#9F35FF"));
                model.setHintTextColor(Color.parseColor("#9F35FF"));
                // licensenum.setText("");
                // carbrand.setText("");
                // color.setText("");
                // model.setText("");
                licensenum.setInputType(InputType.TYPE_CLASS_TEXT);
                carbrand.setInputType(InputType.TYPE_CLASS_TEXT);
                color.setInputType(InputType.TYPE_CLASS_TEXT);
                model.setInputType(InputType.TYPE_CLASS_TEXT);

                // start!
                selectcarinfo(UserPhoneNumber);
                // end!
            }
            confirm();
        }

        private void selectcarinfo(final String phonenum) {
            // TODO Auto-generated method stub
            String carinfo_selectrequest_baseurl = getString(R.string.uri_base)
                    + getString(R.string.uri_CarInfo) + getString(R.string.uri_selectcarinfo_action);

            Log.d("carinfo_selectrequest_baseurl", carinfo_selectrequest_baseurl);
            StringRequest stringRequest = new StringRequest(Request.Method.POST, carinfo_selectrequest_baseurl,
                    new Response.Listener<String>() {

                        @Override
                        public void onResponse(String response) {
                            // TODO Auto-generated method stub
                            Log.d("carinfo_select", response);
                            String jas_id = null;
                            JSONObject json1 = null;
                            try {
                                json1 = new JSONObject(response);
                                JSONObject json = json1.getJSONObject("result");
                                jas_id = json.getString("id");

                                if (jas_id.compareTo("") != 0) { // 

                                    carinfochoosing_type = 2;

                                    carbrand.setText(json.getString("carBrand"));
                                    model.setText(json.getString("carModel"));
                                    licensenum.setText(json.getString("carNum"));
                                    color.setText(json.getString("carColor"));

                                }
                                {
                                    carinfochoosing_type = 1;
                                }

                            } catch (JSONException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }

                    }, new Response.ErrorListener() {

                        @Override
                        public void onErrorResponse(VolleyError error) {
                            // TODO Auto-generated method stub
                            Log.e("carinfo_selectresult_result", error.getMessage(), error);
                        }
                    }) {
                protected Map<String, String> getParams() {
                    Map<String, String> params = new HashMap<String, String>();
                    params.put("phonenum", phonenum);
                    return params;
                }
            };

            queue.add(stringRequest);
        }
    });

    sure.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

            if (longway_group.getCheckedRadioButtonId() == passangerRadioButton.getId())
                userrole = "p";
            else
                userrole = "d";

            // start!
            Context phonenumber = LongWayActivity.this;
            SharedPreferences filename = phonenumber
                    .getSharedPreferences(getString(R.string.PreferenceDefaultName), Context.MODE_PRIVATE);
            username = filename.getString("refreshfilename", "0");
            longway_request(username, userrole, datebutton.getText().toString(),
                    startplace.getText().toString(), endplace.getText().toString(),
                    noteinfo.getText().toString());
            // end!
        }

        private void longway_request(final String longway_phonenum, final String longway_userrole,
                final String longway_startdate, final String longway_startplace,
                final String longway_destination, final String longway_noteinfo) {
            // TODO Auto-generated method stub

            String longway_addrequest_baseurl = getString(R.string.uri_base)
                    + getString(R.string.uri_LongwayPublish) + getString(R.string.uri_addpublish_action);
            // + "phonenum=" + longway_phonenum
            // + "&userrole=" + longway_userrole
            // + "&startdate=" + standard_longway_startdate
            // + "&startplace=" + longway_startplace
            // + "&destination=" + longway_destination
            // + "&noteinfo=" + longway_noteinfo;

            // Log.d("longway_baseurl",longway_addrequest_baseurl);

            StringRequest stringRequest = new StringRequest(Request.Method.POST, longway_addrequest_baseurl,
                    new Response.Listener<String>() {

                        @Override
                        public void onResponse(String response) {
                            Log.d("longway_result", response);
                            JSONObject json1 = null;
                            try {
                                json1 = new JSONObject(response);
                                requestok = json1.getBoolean("result");
                            } catch (JSONException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                            if (requestok == true) {

                                if (carinfochoosing_type == 1) {
                                    // add
                                    // start!
                                    carinfo(longway_phonenum, licensenum.getText().toString(),
                                            carbrand.getText().toString(), model.getText().toString(),
                                            color.getText().toString(), String.valueOf(sum), 1);
                                    // end!
                                } else {
                                    // update
                                    // start!
                                    carinfo(longway_phonenum, licensenum.getText().toString(),
                                            carbrand.getText().toString(), model.getText().toString(),
                                            color.getText().toString(), String.valueOf(sum), 2);
                                    // end!
                                }

                                Intent sure = new Intent(LongWayActivity.this, OrderResponseActivity.class);
                                sure.putExtra(getString(R.string.request_response), "true");
                                sure.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                startActivity(sure);
                            } else {
                                // Toast errorinfo =
                                // Toast.makeText(getApplicationContext(),
                                // "", Toast.LENGTH_LONG);
                                // errorinfo.show();
                                Intent sure = new Intent(LongWayActivity.this, OrderResponseActivity.class);
                                sure.putExtra(getString(R.string.request_response), "false");
                                sure.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                startActivity(sure);
                            }
                        }
                    }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Log.e("longway_result", error.getMessage(), error);
                            // Toast errorinfo = Toast.makeText(null,
                            // "", Toast.LENGTH_LONG);
                            // errorinfo.show();
                            Intent sure = new Intent(LongWayActivity.this, OrderResponseActivity.class);
                            sure.putExtra(getString(R.string.request_response), "false");
                            sure.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            startActivity(sure);
                        }
                    }) {
                protected Map<String, String> getParams() {
                    // POSTgetParams

                    // start
                    try {
                        test_date = primary_date.parse(longway_startdate);
                        standard_longway_startdate = standard_date.format(test_date);
                    } catch (ParseException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    // end!

                    Map<String, String> params = new HashMap<String, String>();
                    params.put(getString(R.string.uri_phonenum), longway_phonenum);
                    params.put(getString(R.string.uri_userrole), longway_userrole);
                    params.put(getString(R.string.uri_startplace), longway_startplace);
                    params.put(getString(R.string.uri_destination), longway_destination);
                    params.put(getString(R.string.uri_startdate), standard_longway_startdate);
                    params.put(getString(R.string.uri_noteinfo), longway_noteinfo);

                    return params;
                }
            };
            queue.add(stringRequest);
        }
    });

    // start!
    shortway.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent shortway = new Intent(LongWayActivity.this, ShortWayActivity.class);
            startActivity(shortway);
        }
    });

    longway.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
        }
    });

    commute.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent commute = new Intent(LongWayActivity.this, CommuteActivity.class);
            startActivity(commute);
        }
    });

    // end!

    increase.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            sum++;
            s1.setText("" + sum);
            confirm();
        }
    });

    decrease.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            sum--;
            if (sum < 0) {
                sum = 0;
            }
            s1.setText("" + sum);
            confirm();
        }
    });

    datebutton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            showDialog(DATE_DIALOG);
        }
    });
}

From source file:com.alivenet.dmvtaxi.FcmUtil.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*www . j av  a 2s  .c  om*/
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void sendNotification(String message) {
    SharedPreference sharedPreference = new SharedPreference();

    if (splitnotifiaction_flag) {
        intent = new Intent(this, AcceptNotificationUIwork.class);
        if (flag == true) {
            intent.putExtra("ridedriverInfo", MyApplication.rideDriverComplete);
            intent.putExtra("flag", flag);
        }
    } else {

        intent = new Intent(this, DeashboardActivity.class);
        if (flag == true) {
            intent.putExtra("ridedriverInfo", MyApplication.rideDriverComplete);
            intent.putExtra("flag", flag);
        }
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Notification").setContentText(message)
                .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

        NotificationManager notificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

    }
}

From source file:com.androzic.MapActivity.java

/** Called when the activity is first created. */
@SuppressLint("ShowToast")
@Override//from w  w  w  . ja  va2  s.com
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Log.e(TAG, "onCreate()");

    ready = false;
    isFullscreen = false;

    backToast = Toast.makeText(this, R.string.backQuit, Toast.LENGTH_SHORT);
    finishHandler = new FinishHandler(this);

    application = (Androzic) getApplication();

    // FIXME Should find a better place for this
    application.mapObjectsOverlay = new MapObjectsOverlay(this);

    // check if called after crash
    if (!application.mapsInited) {
        restarting = true;
        startActivity(new Intent(this, Splash.class)
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
                .putExtras(getIntent()));
        finish();
        return;
    }

    application.setMapActivity(this);

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    setRequestedOrientation(Integer.parseInt(settings.getString(getString(R.string.pref_orientation), "-1")));
    settings.registerOnSharedPreferenceChangeListener(this);
    Resources resources = getResources();

    if (settings.getBoolean(getString(R.string.pref_hideactionbar),
            resources.getBoolean(R.bool.def_hideactionbar))) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }

    panelActions = getResources().getStringArray(R.array.panel_action_values);

    setContentView(R.layout.act_main);
    coordinates = (TextView) findViewById(R.id.coordinates);
    satInfo = (TextView) findViewById(R.id.sats);
    currentFile = (TextView) findViewById(R.id.currentfile);
    mapZoom = (TextView) findViewById(R.id.currentzoom);
    waypointName = (TextView) findViewById(R.id.waypointname);
    waypointExtra = (TextView) findViewById(R.id.waypointextra);
    routeName = (TextView) findViewById(R.id.routename);
    routeExtra = (TextView) findViewById(R.id.routeextra);
    speedValue = (TextView) findViewById(R.id.speed);
    speedUnit = (TextView) findViewById(R.id.speedunit);
    trackValue = (TextView) findViewById(R.id.track);
    trackUnit = (TextView) findViewById(R.id.trackunit);
    elevationValue = (TextView) findViewById(R.id.elevation);
    elevationUnit = (TextView) findViewById(R.id.elevationunit);
    distanceValue = (TextView) findViewById(R.id.distance);
    distanceUnit = (TextView) findViewById(R.id.distanceunit);
    xtkValue = (TextView) findViewById(R.id.xtk);
    xtkUnit = (TextView) findViewById(R.id.xtkunit);
    bearingValue = (TextView) findViewById(R.id.bearing);
    bearingUnit = (TextView) findViewById(R.id.bearingunit);
    turnValue = (TextView) findViewById(R.id.turn);
    trackBar = (SeekBar) findViewById(R.id.trackbar);
    waitBar = (TextView) findViewById(R.id.waitbar);
    map = (MapView) findViewById(R.id.mapview);

    // set button actions
    findViewById(R.id.zoomin).setOnClickListener(this);
    findViewById(R.id.zoomout).setOnClickListener(this);
    findViewById(R.id.nextmap).setOnClickListener(this);
    findViewById(R.id.prevmap).setOnClickListener(this);
    findViewById(R.id.maps).setOnClickListener(this);
    findViewById(R.id.waypoints).setOnClickListener(this);
    findViewById(R.id.info).setOnClickListener(this);
    findViewById(R.id.follow).setOnClickListener(this);
    findViewById(R.id.locate).setOnClickListener(this);
    findViewById(R.id.tracking).setOnClickListener(this);
    findViewById(R.id.expand).setOnClickListener(this);
    findViewById(R.id.finishedit).setOnClickListener(this);
    findViewById(R.id.addpoint).setOnClickListener(this);
    findViewById(R.id.insertpoint).setOnClickListener(this);
    findViewById(R.id.removepoint).setOnClickListener(this);
    findViewById(R.id.orderpoints).setOnClickListener(this);
    findViewById(R.id.finishtrackedit).setOnClickListener(this);
    findViewById(R.id.cutafter).setOnClickListener(this);
    findViewById(R.id.cutbefore).setOnClickListener(this);

    Panel panel = (Panel) findViewById(R.id.panel);
    panel.setOnPanelListener(this);
    panel.setInterpolator(new ExpoInterpolator(Type.OUT));

    wptQuickAction = new QuickAction3D(this, QuickAction3D.VERTICAL);
    wptQuickAction.addActionItem(new ActionItem(qaAddWaypointToRoute, getString(R.string.menu_addtoroute),
            resources.getDrawable(R.drawable.ic_action_add)));
    wptQuickAction.setOnActionItemClickListener(waypointActionItemClickListener);

    rteQuickAction = new QuickAction3D(this, QuickAction3D.VERTICAL);
    rteQuickAction.addActionItem(new ActionItem(qaNavigateToWaypoint, getString(R.string.menu_thisnavpoint),
            resources.getDrawable(R.drawable.ic_action_directions)));
    rteQuickAction.setOnActionItemClickListener(routeActionItemClickListener);

    mobQuickAction = new QuickAction3D(this, QuickAction3D.VERTICAL);
    mobQuickAction.addActionItem(new ActionItem(qaNavigateToMapObject, getString(R.string.menu_navigate),
            resources.getDrawable(R.drawable.ic_action_directions)));
    mobQuickAction.setOnActionItemClickListener(mapObjectActionItemClickListener);

    trackBar.setOnSeekBarChangeListener(this);

    map.initialize(application);

    dimView = new RelativeLayout(this);

    String navWpt = settings.getString(getString(R.string.nav_wpt), "");
    if (!"".equals(navWpt) && savedInstanceState == null) {
        Intent intent = new Intent(getApplicationContext(), NavigationService.class)
                .setAction(NavigationService.NAVIGATE_MAPOBJECT);
        intent.putExtra(NavigationService.EXTRA_NAME, navWpt);
        intent.putExtra(NavigationService.EXTRA_LATITUDE,
                (double) settings.getFloat(getString(R.string.nav_wpt_lat), 0));
        intent.putExtra(NavigationService.EXTRA_LONGITUDE,
                (double) settings.getFloat(getString(R.string.nav_wpt_lon), 0));
        intent.putExtra(NavigationService.EXTRA_PROXIMITY, settings.getInt(getString(R.string.nav_wpt_prx), 0));
        startService(intent);
    }

    String navRoute = settings.getString(getString(R.string.nav_route), "");
    if (!"".equals(navRoute) && settings.getBoolean(getString(R.string.pref_navigation_loadlast),
            getResources().getBoolean(R.bool.def_navigation_loadlast)) && savedInstanceState == null) {
        int ndir = settings.getInt(getString(R.string.nav_route_dir), 0);
        int nwpt = settings.getInt(getString(R.string.nav_route_wpt), -1);
        try {
            int rt = -1;
            Route route = application.getRouteByFile(navRoute);
            if (route != null) {
                route.show = true;
                rt = application.getRouteIndex(route);
            } else {
                File rtf = new File(navRoute);
                // FIXME It's bad - it can be not a first route in a file
                route = OziExplorerFiles.loadRoutesFromFile(rtf, application.charset).get(0);
                rt = application.addRoute(route);
            }
            RouteOverlay newRoute = new RouteOverlay(this, route);
            application.routeOverlays.add(newRoute);
            startService(new Intent(this, NavigationService.class).setAction(NavigationService.NAVIGATE_ROUTE)
                    .putExtra(NavigationService.EXTRA_ROUTE_INDEX, rt)
                    .putExtra(NavigationService.EXTRA_ROUTE_DIRECTION, ndir)
                    .putExtra(NavigationService.EXTRA_ROUTE_START, nwpt));
        } catch (Exception e) {
            Log.e(TAG, "Failed to start navigation", e);
        }
    }

    // set activity preferences
    onSharedPreferenceChanged(settings, getString(R.string.pref_exit));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitprecision));
    // set map preferences
    onSharedPreferenceChanged(settings, getString(R.string.pref_mapadjacent));
    onSharedPreferenceChanged(settings, getString(R.string.pref_mapcropborder));
    onSharedPreferenceChanged(settings, getString(R.string.pref_mapdrawborder));
    onSharedPreferenceChanged(settings, getString(R.string.pref_cursorcolor));
    onSharedPreferenceChanged(settings, getString(R.string.pref_grid_mapshow));
    onSharedPreferenceChanged(settings, getString(R.string.pref_grid_usershow));
    onSharedPreferenceChanged(settings, getString(R.string.pref_grid_preference));
    onSharedPreferenceChanged(settings, getString(R.string.pref_panelactions));

    if (getIntent().getExtras() != null)
        onNewIntent(getIntent());

    ready = true;
}