Example usage for android.widget ArrayAdapter setDropDownViewResource

List of usage examples for android.widget ArrayAdapter setDropDownViewResource

Introduction

In this page you can find the example usage for android.widget ArrayAdapter setDropDownViewResource.

Prototype

public void setDropDownViewResource(@LayoutRes int resource) 

Source Link

Document

Sets the layout resource to create the drop down views.

Usage

From source file:com.busticket.amedora.busticketsrl.TicketingHomeActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.layout_ticket_home);
    myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(myToolbar);//  ww w  .  j  a va 2  s . c  o  m
    //synchTrips();
    assert getSupportActionBar() != null;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    spBoard = (Spinner) findViewById(R.id.spBoard);
    spBuses = (Spinner) findViewById(R.id.spBusNo);
    spTrips = (Spinner) findViewById(R.id.spTripType);
    spHighlight = (Spinner) findViewById(R.id.spHighlight);
    mAccount = CreateSyncAccount(this);
    mQueue = Volley.newRequestQueue(getApplicationContext());
    rQSyncTicket = Volley.newRequestQueue(getApplicationContext());
    rQSyncTicketSynch = Volley.newRequestQueue(getApplicationContext());
    rQSyncBalance = Volley.newRequestQueue(getApplicationContext());
    rqTrip = Volley.newRequestQueue(getApplicationContext());
    rQSyncTicketing = Volley.newRequestQueue(getApplicationContext());
    rQSyncTicketingSynch = Volley.newRequestQueue(getApplicationContext());
    //Key methods needed to be sent to server on activity created
    syncTicketing();
    syncTickets();

    apps = db.getApp(Installation.appId(getApplicationContext()));
    EMAIL = apps.getRoute_name();
    NAME = "CODE: " + apps.getAgent_code().toUpperCase() + " Trip: " + apps.getTripCount();
    // Get the content resolver for your app
    mResolver = getContentResolver();
    /*
     * Turn on periodic syncing
     */

    mTitle = mDrawerTitle = getTitle();
    ContentResolver.addPeriodicSync(CreateSyncAccount(this), AUTHORITY, Bundle.EMPTY, SYNC_INTERVAL);

    String[] tdata = populateTerminals();
    String[] bdata = populateBuses();
    ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, tdata);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spBoard.setAdapter(adapter);/**/

    ArrayAdapter Hadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, tdata);
    Hadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spHighlight.setAdapter(Hadapter);

    ArrayAdapter gadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, bdata);
    gadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spBuses.setAdapter(gadapter);

    ArrayAdapter<CharSequence> tadapter = ArrayAdapter.createFromResource(this, R.array.tripTypes,
            android.R.layout.simple_spinner_item);
    tadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    /*ArrayAdapter badapter =new ArrayAdapter(this,android.R.layout.simple_spinner_item,bdata);
    badapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);*/
    spTrips.setAdapter(tadapter);

    spBuses.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE);
            //((TextView) parent.getChildAt(0)).setTextSize(25);
            bus = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    spBoard.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE);
            //((TextView) parent.getChildAt(0)).setTextSize(25);
            board = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    spHighlight.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE);
            //((TextView) parent.getChildAt(0)).setTextSize(25);
            highlight = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    spTrips.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE);
            //((TextView) parent.getChildAt(0)).setTextSize(25);
            trip = parent.getItemAtPosition(position).toString();

        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    btnGenerate = (Button) findViewById(R.id.btnGenerate);

    btnGenerate.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // get a new activity to show invoice preview
            sendData();
        }
    });
    mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View

    mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are of fixed size

    mAdapter = new DrawerAdapter(TITLES, ICONS, NAME, EMAIL, PROFILE); // Creating the Adapter of MyAdapter class(which we are going to see in a bit)
    // And passing the titles,icons,header view name, header view email,
    // and header view profile picture

    // Setting the adapter to RecyclerView
    //mRecyclerView.setLayoutManager(mLayoutManager);                 // Setting the layout Manager
    LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setAdapter(mAdapter);
    Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout);
    // Drawer object Assigned to the view

    mDrawerToggle = new ActionBarDrawerToggle(this, Drawer, toolbar, R.string.openDrawer,
            R.string.closeDrawer) {
        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            // code here will execute once the drawer is opened( As I dont want anything happened whe drawer is
            // open I am not going to put anything here)
            invalidateOptionsMenu();
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            // Code here will execute once drawer is closed
            invalidateOptionsMenu();
        }
    }; // Drawer Toggle Object Made
    Drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle
    mDrawerToggle.syncState(); // Finally we set the drawer toggle sync State

    final GestureDetector mGestureDetector = new GestureDetector(TicketingHomeActivity.this,
            new GestureDetector.SimpleOnGestureListener() {

                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    return true;
                }

            });

    mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
        @Override
        public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
            View child = recyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY());
            if (child != null && mGestureDetector.onTouchEvent(motionEvent)) {
                Drawer.closeDrawers();
                if (recyclerView.getChildPosition(child) == 1) {

                } else if (recyclerView.getChildPosition(child) == 2) {
                    Intent intent = new Intent(TicketingHomeActivity.this, AccountActivity.class);
                    startActivity(intent);
                } else if (recyclerView.getChildPosition(child) == 3) {
                    Intent intent = new Intent(TicketingHomeActivity.this, TicketListActivity.class);
                    startActivity(intent);
                } else if (recyclerView.getChildPosition(child) == 4) {

                    syncTicketingSynchronize();
                    syncTicketsSynchronize();
                    synchAccount();
                    insertBuses();
                    //insertTerminals();

                    //syncTickets();

                    //dialog = ProgressDialog.show(TicketingHomeActivity.this, "", "Synchronizing App Data. Please wait...", true);
                    /*new Thread(new Runnable() {
                    @Override
                    public void run() {
                            
                        Looper.prepare();
                            
                        final Handler handler = new Handler();
                        handler.postDelayed(new Runnable() {
                            @Override
                            public void run() {*/

                    // insertTerminals();

                    // insertBuses();
                    //getTickets();

                    //Toast.makeText(TicketingHomeActivity.this, "Looper startes ", Toast.LENGTH_SHORT).show();
                    /*handler.removeCallbacks(this);
                            
                    Looper.myLooper().quit();
                    }
                    }, 30000);
                            
                    Looper.loop();
                    }
                    }).start();*/

                } else if (recyclerView.getChildPosition(child) == 5) {
                    if (apps.getLicenceNo() != null) {
                        Intent intent = new Intent(TicketingHomeActivity.this, TripHomeActivity.class);
                        startActivity(intent);

                    } else {
                        //Intent intent = new Intent(TicketingHomeActivity.this,TestPrintActivity.class);
                        //startActivity(intent);
                        Toast.makeText(TicketingHomeActivity.this,
                                "Application is in default mode you cannot use this menu", Toast.LENGTH_SHORT)
                                .show();
                    }

                } else if (recyclerView.getChildPosition(child) == 6) {
                    Intent intent = new Intent(TicketingHomeActivity.this, LogoutActivity.class);
                    startActivity(intent);
                    // Toast.makeText(TicketingHomeActivity.this, "The Item Clicked is: " + recyclerView.getChildPosition(child), Toast.LENGTH_SHORT).show();
                }
                return true;
            }
            return false;
        }

        @Override
        public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {

        }
    });
    List<Ticket> issuedTickets = db.getIssuedTickets();
    Log.e("SYNC LOG", issuedTickets.toString());
}

From source file:com.application.akscorp.yandextranslator2017.TranslateScreen.java

/**
 * Init toolbar with spinner. Spinner contains languages list for translate function. Contains text change listener.
 *///from   w ww  .j  a v  a 2s  .  com
private void ToolBarController() {
    CheckLanguagesListCorrect();
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item,
            LangsTranslateNameSpinner);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    From = (Spinner) TranslateScreen.findViewById(R.id.language_from);
    From.setAdapter(adapter);
    From.setSelection(FromLang, true);
    From.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            FromLang = position;
            if (IsTranslateEnable && myApp.AUTOTRANSLATE_ENABLE) {
                IsTranslateEnable = false;
                TranslateWork();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {

        }
    });

    ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_spinner_item, LangsTranslateNameSpinner);
    adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    To = (Spinner) TranslateScreen.findViewById(R.id.language_to);
    To.setAdapter(adapter2);
    To.setSelection(ToLang, true);
    To.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ToLang = position;

            final SharedPreferences sPref = getActivity().getPreferences(MODE_PRIVATE);
            SharedPreferences.Editor ed = sPref.edit();
            ed.putString("LAST_LANGUAGE_TRANSLATE_CODE", LangsCodeSpinner[ToLang]);
            ed.commit();

            if (IsTranslateEnable && myApp.AUTOTRANSLATE_ENABLE) {
                IsTranslateEnable = false;
                TranslateWork();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
}

From source file:com.xperia64.timidityae.PlayerFragment.java

@SuppressLint("InflateParams")
public void showMidiDialog() {
    AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
    View v = getActivity().getLayoutInflater().inflate(R.layout.midi_options, null);
    Button speedUp = (Button) v.findViewById(R.id.speedUp);
    Button slowDown = (Button) v.findViewById(R.id.slowDown);
    Button keyUp = (Button) v.findViewById(R.id.keyUp);
    Button keyDown = (Button) v.findViewById(R.id.keyDown);
    Button vplus = (Button) v.findViewById(R.id.vplus);
    Button vminus = (Button) v.findViewById(R.id.vminus);
    Button export = (Button) v.findViewById(R.id.exportButton);
    Button saveCfg = (Button) v.findViewById(R.id.saveCfg);
    Button loadCfg = (Button) v.findViewById(R.id.loadCfg);
    Button savedefCfg = (Button) v.findViewById(R.id.savedefCfg);
    final Button deldefCfg = (Button) v.findViewById(R.id.deldefCfg);
    deldefCfg.setEnabled(new File(mActivity.currSongName + ".def.tcf").exists()
            || new File(mActivity.currSongName + ".def.tzf").exists());
    tempo = (TextView) v.findViewById(R.id.tempoText);
    pitch = (TextView) v.findViewById(R.id.pitchText);
    voices = (TextView) v.findViewById(R.id.voiceText);

    tempo.setText(String.format(getResources().getString(R.string.mop_tempo), JNIHandler.ttr,
            (int) (500000 / (double) JNIHandler.tt * 120 * (double) JNIHandler.ttr / 100 + 0.5)));
    pitch.setText(String.format(getResources().getString(R.string.mop_pitch),
            ((JNIHandler.koffset > 0) ? "+" : "") + Integer.toString(JNIHandler.koffset)));
    voices.setText(//  w  ww  .  j a v a2 s  .  c  o  m
            String.format(getResources().getString(R.string.mop_voice), JNIHandler.voice, JNIHandler.maxvoice));
    speedUp.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            JNIHandler.controlTimidity(17, 1);
            JNIHandler.waitUntilReady();
            JNIHandler.tb++;
        }

    });
    slowDown.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            JNIHandler.controlTimidity(18, 1);
            JNIHandler.waitUntilReady();
            JNIHandler.tb--;
        }

    });
    keyUp.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            JNIHandler.controlTimidity(15, 1);
            JNIHandler.waitUntilReady();
        }

    });
    keyDown.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            JNIHandler.controlTimidity(16, -1);
            JNIHandler.waitUntilReady();
        }

    });
    vplus.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            JNIHandler.controlTimidity(19, 5);
            JNIHandler.waitUntilReady();
        }

    });
    vminus.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            JNIHandler.controlTimidity(20, 5);
            JNIHandler.waitUntilReady();
        }

    });
    export.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            mActivity.dynExport();
        }

    });
    saveCfg.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            mActivity.saveCfg();
        }

    });
    loadCfg.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            mActivity.loadCfg();
        }

    });
    savedefCfg.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            String value1;
            String value2;
            boolean alreadyExists = (new File(mActivity.currSongName + ".def.tcf").exists()
                    || new File(mActivity.currSongName + ".def.tzf").exists());
            boolean aWrite = true;
            String needRename1 = null;
            String needRename2 = null;
            String probablyTheRoot = "";
            String probablyTheDirectory = "";
            try {
                if (Globals.compressCfg)
                    new FileOutputStream(mActivity.currSongName + ".def.tzf", true).close();
                else
                    new FileOutputStream(mActivity.currSongName + ".def.tcf", true).close();
            } catch (FileNotFoundException e) {
                aWrite = false;
            } catch (IOException e) {
                e.printStackTrace();
            }
            final boolean canWrite = aWrite;
            if (!alreadyExists && canWrite) {
                new File(mActivity.currSongName + ".def.tcf").delete();
                new File(mActivity.currSongName + ".def.tzf").delete();
            }

            if (canWrite && new File(mActivity.currSongName).canWrite()) {
                value1 = mActivity.currSongName + (Globals.compressCfg ? ".def.tzf" : ".def.tcf");
                value2 = mActivity.currSongName + (Globals.compressCfg ? ".def.tcf" : ".def.tzf");
            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Globals.theFold != null) {
                //TODO
                // Write the file to getExternalFilesDir, then move it with the Uri
                // We need to tell JNIHandler that movement is needed.
                // This is pretty much done now?
                String[] tmp = Globals.getDocFilePaths(getActivity(), mActivity.currSongName);
                probablyTheDirectory = tmp[0];
                probablyTheRoot = tmp[1];
                if (probablyTheDirectory.length() > 1) {
                    needRename1 = (mActivity.currSongName).substring(
                            mActivity.currSongName.indexOf(probablyTheRoot) + probablyTheRoot.length())
                            + (Globals.compressCfg ? ".def.tzf" : ".def.tcf");
                    needRename2 = (mActivity.currSongName).substring(
                            mActivity.currSongName.indexOf(probablyTheRoot) + probablyTheRoot.length())
                            + (Globals.compressCfg ? ".def.tcf" : ".def.tzf");
                    value1 = probablyTheDirectory
                            + mActivity.currSongName.substring(mActivity.currSongName.lastIndexOf('/'))
                            + (Globals.compressCfg ? ".def.tzf" : ".def.tcf");
                    value2 = probablyTheDirectory
                            + mActivity.currSongName.substring(mActivity.currSongName.lastIndexOf('/'))
                            + (Globals.compressCfg ? ".def.tcf" : ".def.tzf");
                } else {
                    Toast.makeText(getActivity(),
                            "Could not write config file. Did you give Timidity write access to the root of your external sd card?",
                            Toast.LENGTH_SHORT).show();
                    return;
                }
            } else {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    Toast.makeText(getActivity(),
                            "Could not write config file. Did you give Timidity write access to the root of your external sd card?",
                            Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(getActivity(), "Could not write config file. Permission denied.",
                            Toast.LENGTH_SHORT).show();
                }
                return;
            }
            final String finalval1 = value1;
            final String finalval2 = value2;
            final String needToRename1 = needRename1;
            final String needToRename2 = needRename2;
            final String probRoot = probablyTheRoot;
            if (alreadyExists) {
                AlertDialog dialog = new AlertDialog.Builder(mActivity).create();
                dialog.setTitle("Warning");
                dialog.setMessage("Overwrite default config file?");
                dialog.setCancelable(false);
                dialog.setButton(DialogInterface.BUTTON_POSITIVE,
                        getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int buttonId) {
                                if (!canWrite && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                    if (needToRename1 != null) {
                                        Globals.tryToDeleteFile(getActivity(), probRoot + needToRename1);
                                        Globals.tryToDeleteFile(getActivity(), finalval1);
                                        Globals.tryToDeleteFile(getActivity(), probRoot + needToRename2);
                                        Globals.tryToDeleteFile(getActivity(), finalval2);
                                    } else {
                                        Globals.tryToDeleteFile(getActivity(), finalval1);
                                        Globals.tryToDeleteFile(getActivity(), finalval2);
                                    }
                                } else {
                                    new File(mActivity.currSongName + ".def.tcf").delete();
                                    new File(mActivity.currSongName + ".def.tzf").delete();
                                }
                                mActivity.localfinished = false;
                                mActivity.saveCfgPart2(finalval1, needToRename1);
                                deldefCfg.setEnabled(true);
                                /*Intent new_intent = new Intent();
                                new_intent.setAction(getResources().getString(R.string.msrv_rec));
                                new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 16);
                                new_intent.putExtra(getResources().getString(R.string.msrv_outfile), mActivity.currSongName+".def.tcf");
                                getActivity().sendBroadcast(new_intent);
                                deldefCfg.setEnabled(true);*/
                            }
                        });
                dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.no),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int buttonId) {

                            }
                        });
                dialog.show();

            } else {
                /*Intent new_intent = new Intent();
                 new_intent.setAction(getResources().getString(R.string.msrv_rec));
                 new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 16);
                 new_intent.putExtra(getResources().getString(R.string.msrv_outfile), mActivity.currSongName+".def.tcf");
                 getActivity().sendBroadcast(new_intent);
                 deldefCfg.setEnabled(true);*/
                mActivity.localfinished = false;
                mActivity.saveCfgPart2(finalval1, needToRename1);
                deldefCfg.setEnabled(true);
            }
        }

    });

    deldefCfg.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            if (new File(mActivity.currSongName + ".def.tcf").exists()
                    || new File(mActivity.currSongName + ".def.tzf").exists()) {
                boolean aWrite = true;
                try {
                    if (Globals.compressCfg)
                        new FileOutputStream(mActivity.currSongName + ".def.tzf", true).close();
                    else
                        new FileOutputStream(mActivity.currSongName + ".def.tcf", true).close();
                } catch (FileNotFoundException e) {
                    aWrite = false;
                } catch (IOException e) {
                    e.printStackTrace();
                }
                final boolean canWrite = aWrite;
                AlertDialog dialog = new AlertDialog.Builder(mActivity).create();
                dialog.setTitle("Warning");
                dialog.setMessage("Really delete default config file?");
                dialog.setCancelable(false);
                dialog.setButton(DialogInterface.BUTTON_POSITIVE,
                        getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int buttonId) {

                                if (!canWrite && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                    Globals.tryToDeleteFile(getActivity(), mActivity.currSongName + ".def.tzf");
                                    Globals.tryToDeleteFile(getActivity(), mActivity.currSongName + ".def.tcf");
                                } else {
                                    new File(mActivity.currSongName + ".def.tcf").delete();
                                    new File(mActivity.currSongName + ".def.tzf").delete();
                                }
                                deldefCfg.setEnabled(false);
                            }
                        });
                dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.no),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int buttonId) {

                            }
                        });
                dialog.show();

            }
        }

    });

    final Spinner x = (Spinner) v.findViewById(R.id.resampSpinner);
    List<String> arrayAdapter = new ArrayList<String>();
    for (String yyy : Globals.sampls)
        arrayAdapter.add(yyy);
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_spinner_item, arrayAdapter);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    x.setAdapter(dataAdapter);
    firstSelection = true;
    x.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int pos, long id) {
            if (firstSelection)
                firstSelection = false;
            else {
                JNIHandler.setResampleTimidity(JNIHandler.currsamp = pos);
                JNIHandler.seekTo(JNIHandler.currTime);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {

        }

    });
    x.setSelection(JNIHandler.currsamp);
    if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH)
        v.setBackgroundColor(Globals.theme == 1 ? Color.WHITE : Color.BLACK);

    b.setView(v);
    b.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    b.setTitle(getActivity().getResources().getString(R.string.mop));
    ddd = b.create();
    ddd.show();

}

From source file:com.sssemil.sonyirremote.ir.ir.java

public void prepItemBrandArray() {
    spinner = ((Spinner) findViewById(R.id.spinner));
    localArrayList1 = new ArrayList();
    boolean edited = false;

    for (File localFile1 : new File(this.irpath).listFiles()) {
        if (localFile1.isDirectory()) {
            if (!localArrayList1.contains(localFile1.getName())) {
                localArrayList1.add(localFile1.getName());
                edited = true;//from  w  w w  . j a  v a 2 s.  c  o m
            }
        }

        if (edited) {
            ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_spinner_item, localArrayList1);
            dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(dataAdapter);
        }
    }
}

From source file:com.sssemil.sonyirremote.ir.ir.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        setContentView(R.layout.settings_ir);
        main = false;/*from   w ww .  jav a  2s. c o  m*/

        final GetAwItems getAwItems1 = new GetAwItems(ir.this);
        String ret = getAwItems1.execute().get();

        spinner6 = ((Spinner) findViewById(R.id.spinner6));
        spinner6.setSelection(0);

        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
                ar);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner6.setAdapter(dataAdapter);

        prepItemBrandArray();

        return true;
    } else if (id == R.id.action_about) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getString(R.string.about));
        PackageInfo pInfo = null;
        String version = "?";
        try {
            pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        version = pInfo.versionName;
        builder.setMessage(getResources().getString(R.string.license1) + " v" + version + "\n"
                + getResources().getString(R.string.license2) + "\n"
                + getResources().getString(R.string.license3) + "\n"
                + getResources().getString(R.string.license4));
        builder.setPositiveButton("OK", null);
        AlertDialog dialog = builder.show();

        TextView messageView = (TextView) dialog.findViewById(android.R.id.message);
        messageView.setGravity(Gravity.CENTER);
        return true;
    } else if (id == R.id.action_exit) {
        stopIR();
        System.exit(0);
        return true;
    } else if (id == R.id.action_update) {
        update();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.sssemil.sonyirremote.ir.ir.java

public void onRemoveClick(View view) {
    try {/*from w w  w . j  av a 2  s.c  o m*/
        Toast.makeText(this, item, Toast.LENGTH_SHORT).show();

        String[] remove = { "rm", "-rf", irpath + item };
        try {
            Process p = Runtime.getRuntime().exec(remove);
            Log.i("rm", "Waiting... " + irpath + item);
            p.waitFor();
            Log.i("rm", "Done! " + irpath + item);
        } catch (Exception e) {
            Log.e("rm", "Failed! " + irpath + item);
            e.printStackTrace();
        }

        spinner = ((Spinner) findViewById(R.id.spinner));
        localArrayList1 = new ArrayList();
        localArrayList1.remove(item);
        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
                localArrayList1);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(dataAdapter);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getString(R.string.done));
        builder.setMessage(getString(R.string.done_removing) + " " + item + " " + getString(R.string.files));
        builder.setPositiveButton("OK", null);
        AlertDialog dialog = builder.show();

        TextView messageView = (TextView) dialog.findViewById(android.R.id.message);
        messageView.setGravity(Gravity.CENTER);
    } catch (NullPointerException ex) {
        ex.printStackTrace();
        AlertDialog.Builder adb = new AlertDialog.Builder(this);
        adb.setTitle(getString(R.string.error));
        adb.setMessage(getString(R.string.you_need_to_select));
        adb.setIcon(android.R.drawable.ic_dialog_alert);
        adb.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
            }
        });
        adb.show();
    }
}

From source file:edu.princeton.jrpalmer.asmlibrary.Settings.java

@Override
protected void onResume() {

    if (Util.trafficCop(this))
        finish();//  w  w  w .  j  av a 2s  .c om
    IntentFilter uploadFilter;
    uploadFilter = new IntentFilter(
            getResources().getString(R.string.internal_message_id) + Util.MESSAGE_FIX_UPLOADED);
    uploadReceiver = new UploadReceiver();
    registerReceiver(uploadReceiver, uploadFilter);

    IntentFilter fixFilter;
    fixFilter = new IntentFilter(
            getResources().getString(R.string.internal_message_id) + Util.MESSAGE_FIX_RECORDED);
    fixReceiver = new FixReceiver();
    registerReceiver(fixReceiver, fixFilter);

    shareMyData = PropertyHolder.getShareData();

    toggleParticipationViews(shareMyData);

    int nUploads = PropertyHolder.getNUploads();

    final long participationTime = PropertyHolder.ptCheck();
    participationTimeText.setBase(SystemClock.elapsedRealtime() - participationTime);

    // service button
    boolean isServiceOn = PropertyHolder.isServiceOn();

    mServiceButton.setChecked(isServiceOn);
    mServiceButton.setOnClickListener(new ToggleButton.OnClickListener() {
        public void onClick(View view) {
            if (view.getId() != R.id.service_button)
                return;
            Context context = view.getContext();
            boolean on = ((ToggleButton) view).isChecked();
            String schedule = on ? Util.MESSAGE_SCHEDULE : Util.MESSAGE_UNSCHEDULE;
            // Log.e(TAG, schedule + on);

            // now schedule or unschedule
            Intent intent = new Intent(getString(R.string.internal_message_id) + schedule);
            context.sendBroadcast(intent);
            showSpinner(on, storeMyData);

            if (on && shareMyData) {
                final long ptNow = PropertyHolder.ptStart();
                participationTimeText.setBase(SystemClock.elapsedRealtime() - ptNow);
                participationTimeText.start();

                ContentResolver ucr = getContentResolver();

                ucr.insert(Util.getUploadQueueUri(context), UploadContentValues.createUpload("ONF",
                        "on," + Util.iso8601(System.currentTimeMillis()) + "," + ptNow));
            } else {

                final long ptNow = PropertyHolder.ptStop();
                participationTimeText.setBase(SystemClock.elapsedRealtime() - ptNow);
                participationTimeText.stop();
                // stop uploader
                Intent stopUploaderIntent = new Intent(Settings.this, FileUploader.class);
                // Stop service if it is currently running
                stopService(stopUploaderIntent);

                if (shareMyData) {

                    ContentResolver ucr = getContentResolver();

                    ucr.insert(Util.getUploadQueueUri(context), UploadContentValues.createUpload("ONF",
                            "off," + Util.iso8601(System.currentTimeMillis()) + "," + ptNow));

                }

            }
            // If user turns CountdownDisplay on but GPS is not on, remind
            // user to turn
            // GPS on
            if (on) {
                final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

                if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                    if (!manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
                        buildAlertMessageNoGpsNoNet();
                    } else
                        buildAlertMessageNoGps();
                }
            }

            return;
        }
    });

    // interval spinner
    int intspinner_item = android.R.layout.simple_spinner_item;
    int dropdown_item = android.R.layout.simple_spinner_dropdown_item;
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.interval_array,
            intspinner_item);
    adapter.setDropDownViewResource(dropdown_item);
    mIntervalSpinner.setAdapter(adapter);
    mIntervalSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) {
            int parentId = parent.getId();
            if (parentId != R.id.spinner_interval)
                return;
            if (pos > mInterval.length)
                return;
            if (!PropertyHolder.isServiceOn()) {
                PropertyHolder.setAlarmInterval(mInterval[pos]);
                return;
            }
            PropertyHolder.setAlarmInterval(mInterval[pos]);
            mServiceButton.setChecked(true);

            Intent intent = new Intent(getString(R.string.internal_message_id) + Util.MESSAGE_SCHEDULE);
            Context context = getApplicationContext();
            context.sendBroadcast(intent);
            showSpinner(true, storeMyData);

            if (shareMyData) {
                ContentResolver ucr = getContentResolver();

                ucr.insert(Util.getUploadQueueUri(context), UploadContentValues.createUpload("INT",
                        Util.iso8601(System.currentTimeMillis()) + "," + mInterval[pos]));
            }
        }

        public void onNothingSelected(AdapterView<?> parent) {
            // do nothing
        }
    });
    int pos = ai2pos(PropertyHolder.getAlarmInterval());
    mIntervalSpinner.setSelection(pos);
    showSpinner(isServiceOn, storeMyData);

    // mydata buttons

    // storage spinner

    storageDays = PropertyHolder.getStorageDays();

    mStorageSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) {
            int parentId = parent.getId();
            if (parentId != R.id.spinner_mydata)
                return;
            if (pos > MAX_STORAGE - MIN_STORAGE)
                return;
            PropertyHolder.setStorageDays(pos + MIN_STORAGE);
            PropertyHolder.setStoreMyData((pos + MIN_STORAGE) > 0);
        }

        public void onNothingSelected(AdapterView<?> parent) {
            // do nothing
        }
    });
    int storagepos = storageDays - MIN_STORAGE;
    mStorageSpinner.setSelection(storagepos);

    // NEW STUFF
    mToggleSatRadioGroup = (RadioGroup) findViewById(R.id.toggleSatRadioGroup);
    mToggleIconsRadioGroup = (RadioGroup) findViewById(R.id.toggleIconsRadioGroup);
    mToggleAccRadioGroup = (RadioGroup) findViewById(R.id.toggleAccRadioGroup);
    mLimitStartDateRadioGroup = (RadioGroup) findViewById(R.id.limitStartDateRadioGroup);
    mLimitEndDateRadioGroup = (RadioGroup) findViewById(R.id.limitEndDateRadioGroup);

    Intent i = getIntent();
    if (i.getBooleanExtra(MapMyData.DATES_BUTTON_MESSAGE, false)) {

        RelativeLayout dateSettingsArea = (RelativeLayout) findViewById(R.id.dateSettingsArea);
        dateSettingsArea.setFocusable(true);
        dateSettingsArea.setFocusableInTouchMode(true);
        dateSettingsArea.requestFocus();
    }

    if (shareMyData && isServiceOn) {
        participationTimeText.setBase(SystemClock.elapsedRealtime() - PropertyHolder.ptStart());
        participationTimeText.start();
    }

    nUploadsText.setText(String.valueOf(nUploads));

    if (nUploads >= Util.UPLOADS_TO_PRO && !PropertyHolder.getProVersion()
            && participationTime >= Util.TIME_TO_PRO) {
        Util.createProNotification(context);
        PropertyHolder.setProVersion(true);
        PropertyHolder.setNeedsDebriefingSurvey(true);
    }

    boolean proV = PropertyHolder.getProVersion();

    // 19 December 2013: end of research changes
    mShareDataRadioGroup.check(R.id.sharedataNo);

    mShareDataRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == R.id.sharedataYes) {
                buildSharingOverAnnouncement();
            }
            mShareDataRadioGroup.check(R.id.sharedataNo);
        }
    });

    /*
     * if (proV) {
     * 
     * if (shareMyData) { mShareDataRadioGroup.check(R.id.sharedataYes); if
     * (PropertyHolder.isRegistered() == false ||
     * PropertyHolder.hasConsented() == false) { send2Intro(context); } }
     * else { mShareDataRadioGroup.check(R.id.sharedataNo); }
     * 
     * mShareDataRadioGroup .setOnCheckedChangeListener(new
     * OnCheckedChangeListener() {
     * 
     * @Override public void onCheckedChanged(RadioGroup group, int
     * checkedId) { shareMyData = (checkedId == R.id.sharedataYes);
     * PropertyHolder.setShareData(shareMyData);
     * toggleParticipationViews(shareMyData); final boolean on =
     * PropertyHolder.isServiceOn(); if (shareMyData) { if
     * (PropertyHolder.isRegistered() == false ||
     * PropertyHolder.hasConsented() == false) { send2Intro(context);
     * 
     * } if (on) {
     * 
     * final long ptNow = PropertyHolder.ptStart();
     * participationTimeText.setBase(SystemClock .elapsedRealtime() -
     * ptNow);
     * 
     * participationTimeText.start();
     * 
     * ContentResolver ucr = getContentResolver();
     * 
     * ucr.insert( Util.getUploadQueueUri(context),
     * UploadContentValues.createUpload( "ONF", "on," + Util.iso8601(System
     * .currentTimeMillis()) + "," + ptNow));
     * 
     * } } else {
     * 
     * final long ptNow = PropertyHolder.ptStop();
     * participationTimeText.setBase(SystemClock .elapsedRealtime() -
     * ptNow); participationTimeText.stop(); // stop uploader Intent i = new
     * Intent(Settings.this, FileUploader.class); // Stop service if it is
     * currently running stopService(i);
     * 
     * if (on) { ContentResolver ucr = getContentResolver();
     * 
     * ucr.insert( Util.getUploadQueueUri(context),
     * UploadContentValues.createUpload( "ONF", "off," + Util.iso8601(System
     * .currentTimeMillis()) + "," + ptNow));
     * 
     * }
     * 
     * }
     * 
     * } }); } else { mShareDataRadioGroup.check(R.id.sharedataYes);
     * mShareDataRadioGroup .setOnCheckedChangeListener(new
     * OnCheckedChangeListener() {
     * 
     * @Override public void onCheckedChanged(RadioGroup group, int
     * checkedId) { if (checkedId == R.id.sharedataNo) {
     * mShareDataRadioGroup.check(R.id.sharedataYes);
     * showCurrentlySharingDialog(); } } });
     * 
     * }
     */
    new CheckPendingUploadsSizeTask().execute(context);
    new CheckUserDbSizeTask().execute(context);

    deletePendingUploadsButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ContentResolver cr = getContentResolver();
            final int nDeleted = cr.delete(Util.getUploadQueueUri(context), "1", null);

            // Log.i("Settings", "number of rows deleted=" + nDeleted);
            Util.toast(context, String.valueOf(nDeleted) + " "
                    + getResources().getString(R.string.locations_deleted) + ".");

            updateStorageSizes();

        }

    });

    deleteUserDbButton = (ImageButton) findViewById(R.id.deleteMyDbButton);

    deleteUserDbButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ContentResolver cr = getContentResolver();
            final int nDeleted = cr.delete(Util.getFixesUri(context), "1", null);

            Util.toast(context, String.valueOf(nDeleted) + " "
                    + getResources().getString(R.string.locations_deleted) + ".");
            updateStorageSizes();

        }

    });

    uploadButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (Util.isOnline(context)) {
                Intent i = new Intent(Settings.this, FileUploader.class);
                startService(i);

                new UploadMessageTask().execute(context);
            } else {
                Util.toast(context, getResources().getString(R.string.offline_warning));
            }

        }

    });

    mToggleSatRadioGroup.check(PropertyHolder.getMapSat() ? R.id.toggleSatYes : R.id.toggleSatNo);

    mToggleSatRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            PropertyHolder.setMapSat(checkedId == R.id.toggleSatYes);
        }
    });

    mToggleIconsRadioGroup.check(PropertyHolder.getMapIcons() ? R.id.toggleIconsYes : R.id.toggleIconsNo);

    mToggleIconsRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            PropertyHolder.setMapIcons(checkedId == R.id.toggleIconsYes);
        }
    });

    mToggleAccRadioGroup.check(PropertyHolder.getMapAcc() ? R.id.toggleAccYes : R.id.toggleAccNo);

    mToggleAccRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            PropertyHolder.setMapAcc(checkedId == R.id.toggleAccYes);
        }
    });

    mStartDateButton = (Button) findViewById(R.id.startDateButton);
    mEndDateButton = (Button) findViewById(R.id.endDateButton);

    boolean limitStartDate = PropertyHolder.getLimitStartDate();
    boolean limitEndDate = PropertyHolder.getLimitEndDate();

    if (!limitStartDate)
        mStartDateButton.setVisibility(View.GONE);
    else {
        mStartDateButton.setVisibility(View.VISIBLE);

    }
    if (!limitEndDate)
        mEndDateButton.setVisibility(View.GONE);
    else {
        mEndDateButton.setVisibility(View.VISIBLE);
    }

    mLimitStartDateRadioGroup.check(limitStartDate ? R.id.limitStartDateYes : R.id.limitStartDateNo);

    mLimitStartDateRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            PropertyHolder.setLimitStartDate(checkedId == R.id.limitStartDateYes);

            if (checkedId != R.id.limitStartDateYes)
                mStartDateButton.setVisibility(View.GONE);
            else {
                mStartDateButton.setVisibility(View.VISIBLE);
            }
        }
    });

    mLimitEndDateRadioGroup.check(limitEndDate ? R.id.limitEndDateYes : R.id.limitEndDateNo);

    mLimitEndDateRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            PropertyHolder.setLimitEndDate(checkedId == R.id.limitEndDateYes);

            if (checkedId != R.id.limitEndDateYes)
                mEndDateButton.setVisibility(View.GONE);
            else {
                mEndDateButton.setVisibility(View.VISIBLE);
            }
        }
    });

    mStartDateButton.setText(Util.userDateNoTime(PropertyHolder.getMapStartDate()));
    mStartDateButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            DialogFragment newFragment = new StartDatePickerFragment();
            newFragment.show(getSupportFragmentManager(), "datePicker");

        }

    });

    mEndDateButton.setText(Util.userDateNoTime(PropertyHolder.getMapEndDate()));
    mEndDateButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            DialogFragment newFragment = new EndDatePickerFragment();
            newFragment.show(getSupportFragmentManager(), "datePicker");

        }

    });

    if (PropertyHolder.getNeedsDebriefingSurvey()) {
        buildProAnnouncement();
        PropertyHolder.setNeedsDebriefingSurvey(false);
    }

    super.onResume();

}

From source file:com.asksven.betterbatterystats.StatsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    super.onCreate(savedInstanceState);

    // HockeyApp//  ww  w  .  j ava2 s.c o m
    try {
        MetricsManager.register(getApplication());
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
    }

    //Log.i(TAG, "OnCreated called");
    setContentView(R.layout.stats);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.app_name));

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayUseLogoEnabled(false);

    // set debugging
    if (sharedPrefs.getBoolean("debug_logging", false)) {
        LogSettings.DEBUG = true;
        CommonLogSettings.DEBUG = true;
    } else {
        LogSettings.DEBUG = false;
        CommonLogSettings.DEBUG = false;
    }

    swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);

    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            doRefresh(true);
        }
    });

    ///////////////////////////////////////////////
    // check if we have a new release
    ///////////////////////////////////////////////
    // if yes do some migration (if required) and show release notes
    String strLastRelease = sharedPrefs.getString("last_release", "0");

    String strCurrentRelease = "";
    try {
        PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);

        strCurrentRelease = Integer.toString(pinfo.versionCode);
    } catch (Exception e) {
        // nop strCurrentRelease is set to ""
    }

    // Grant permissions if they are missing and root is available
    if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this)
            || !SysUtils.hasPackageUsageStatsPermission(this)) {
        if ((RootShell.getInstance().isRooted())) {

            // attempt to set perms using pm-comand
            Log.i(TAG, "attempting to grant perms with 'pm grant'");

            String pkg = this.getPackageName();
            RootShell.getInstance().run("pm grant " + pkg + " android.permission.BATTERY_STATS");
            RootShell.getInstance().run("pm grant " + pkg + " android.permission.DUMP");
            RootShell.getInstance().run("pm grant " + pkg + " android.permission.PACKAGE_USAGE_STATS");

            if (SysUtils.hasBatteryStatsPermission(this)) {
                Log.i(TAG, "succeeded");
            } else {
                Log.i(TAG, "failed");
            }
        }
    }

    // Package usage stats were introduced in SDK21 so we need to make the distinction
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // show install as system app screen if root available but perms missing
        if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this)
                || !SysUtils.hasPackageUsageStatsPermission(this)) {
            Intent intentSystemApp = new Intent(this, SystemAppActivity.class);
            this.startActivity(intentSystemApp);
        }
    } else {
        if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this)) {
            Intent intentSystemApp = new Intent(this, SystemAppActivity.class);
            this.startActivity(intentSystemApp);
        }

    }
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    // first start
    if (strLastRelease.equals("0")) {

        boolean firstLaunch = !prefs.getBoolean("launched", false);

        if (firstLaunch) {
            // Save that the app has been launched
            SharedPreferences.Editor editor = prefs.edit();
            editor.putBoolean("launched", true);
            editor.commit();

            // start service to persist reference
            Intent serviceIntent = new Intent(this, WriteUnpluggedReferenceService.class);
            this.startService(serviceIntent);

            // refresh widgets
            Intent intentRefreshWidgets = new Intent(LargeWidgetProvider.WIDGET_UPDATE);
            this.sendBroadcast(intentRefreshWidgets);

        }

        SharedPreferences.Editor updater = sharedPrefs.edit();
        updater.putString("last_release", strCurrentRelease);
        updater.commit();
    } else if (!strLastRelease.equals(strCurrentRelease)) {
        // save the current release to properties so that the dialog won't be shown till next version
        SharedPreferences.Editor updater = sharedPrefs.edit();
        updater.putString("last_release", strCurrentRelease);
        updater.commit();

        // we don't need to delete refs as long as we don't change the database schema
        //         Toast.makeText(this, getString(R.string.info_deleting_refs), Toast.LENGTH_SHORT).show();
        //         ReferenceStore.deleteAllRefs(this);
        //         Intent i = new Intent(this, WriteBootReferenceService.class);
        //         this.startService(i);
        //         i = new Intent(this, WriteUnpluggedReferenceService.class);
        //         this.startService(i);
        ChangeLog cl = new ChangeLog(this);
        cl.getLogDialog().show();

    }

    ///////////////////////////////////////////////
    // retrieve default selections for spinners
    // if none were passed
    ///////////////////////////////////////////////

    m_iStat = Integer.valueOf(sharedPrefs.getString("default_stat", "0"));
    m_refFromName = sharedPrefs.getString("default_stat_type", Reference.UNPLUGGED_REF_FILENAME);

    if (!ReferenceStore.hasReferenceByName(m_refFromName, this)) {

        m_refFromName = Reference.BOOT_REF_FILENAME;
        Toast.makeText(this, getString(R.string.info_fallback_to_boot), Toast.LENGTH_SHORT).show();
    }

    if (LogSettings.DEBUG)
        Log.i(TAG, "onCreate state from preferences: refFrom=" + m_refFromName + " refTo=" + m_refToName);

    try {
        // recover any saved state
        if ((savedInstanceState != null) && (!savedInstanceState.isEmpty())) {
            m_iStat = (Integer) savedInstanceState.getSerializable("stat");
            m_refFromName = (String) savedInstanceState.getSerializable("stattypeFrom");
            m_refToName = (String) savedInstanceState.getSerializable("stattypeTo");

            if (LogSettings.DEBUG)
                Log.i(TAG,
                        "onCreate retrieved saved state: refFrom=" + m_refFromName + " refTo=" + m_refToName);

        }
    } catch (Exception e) {
        m_iStat = Integer.valueOf(sharedPrefs.getString("default_stat", "0"));
        m_refFromName = sharedPrefs.getString("default_stat_type", Reference.UNPLUGGED_REF_FILENAME);

        Log.e(TAG, "Exception: " + e.getMessage());
        DataStorage.LogToFile(LOGFILE, "Exception in onCreate restoring Bundle");
        DataStorage.LogToFile(LOGFILE, e.getMessage());
        DataStorage.LogToFile(LOGFILE, e.getStackTrace());

        Toast.makeText(this, getString(R.string.info_state_recovery_error), Toast.LENGTH_SHORT).show();
    }

    // Handle the case the Activity was called from an intent with paramaters
    Bundle extras = getIntent().getExtras();
    if ((extras != null) && !extras.isEmpty()) {
        // Override if some values were passed to the intent
        if (extras.containsKey(StatsActivity.STAT))
            m_iStat = extras.getInt(StatsActivity.STAT);
        if (extras.containsKey(StatsActivity.STAT_TYPE_FROM))
            m_refFromName = extras.getString(StatsActivity.STAT_TYPE_FROM);
        if (extras.containsKey(StatsActivity.STAT_TYPE_TO))
            m_refToName = extras.getString(StatsActivity.STAT_TYPE_TO);

        if (LogSettings.DEBUG)
            Log.i(TAG, "onCreate state from extra: refFrom=" + m_refFromName + " refTo=" + m_refToName);

        boolean bCalledFromNotification = extras.getBoolean(StatsActivity.FROM_NOTIFICATION, false);

        // Clear the notifications that was clicked to call the activity
        if (bCalledFromNotification) {
            NotificationManager nM = (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE);
            nM.cancel(EventWatcherService.NOTFICATION_ID);
        }
    }

    // Spinner for selecting the stat
    Spinner spinnerStat = (Spinner) findViewById(R.id.spinnerStat);

    ArrayAdapter spinnerStatAdapter = ArrayAdapter.createFromResource(this, R.array.stats,
            R.layout.bbs_spinner_layout); //android.R.layout.simple_spinner_item);
    spinnerStatAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item); // android.R.layout.simple_spinner_dropdown_item);

    spinnerStat.setAdapter(spinnerStatAdapter);
    // setSelection MUST be called after setAdapter
    spinnerStat.setSelection(m_iStat);
    spinnerStat.setOnItemSelectedListener(this);

    ///////////////////////////////////////////////
    // Spinner for Selecting the Stat type
    ///////////////////////////////////////////////
    Spinner spinnerStatType = (Spinner) findViewById(R.id.spinnerStatType);
    m_spinnerFromAdapter = new ReferencesAdapter(this, R.layout.bbs_spinner_layout); //android.R.layout.simple_spinner_item);
    m_spinnerFromAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item); //android.R.layout.simple_spinner_dropdown_item);
    spinnerStatType.setAdapter(m_spinnerFromAdapter);

    try {
        this.setListViewAdapter();
    } catch (BatteryInfoUnavailableException e) {
        Log.e(TAG, "Exception: " + Log.getStackTraceString(e));
        Snackbar.make(findViewById(android.R.id.content), R.string.info_service_connection_error,
                Snackbar.LENGTH_LONG).show();
        //         Toast.makeText(this,
        //               getString(R.string.info_service_connection_error),
        //               Toast.LENGTH_LONG).show();

    } catch (Exception e) {
        //Log.e(TAG, e.getMessage(), e.fillInStackTrace());
        Log.e(TAG, "Exception: " + Log.getStackTraceString(e));
        Toast.makeText(this, getString(R.string.info_unknown_stat_error), Toast.LENGTH_LONG).show();
    }
    // setSelection MUST be called after setAdapter
    spinnerStatType.setSelection(m_spinnerFromAdapter.getPosition(m_refFromName));
    spinnerStatType.setOnItemSelectedListener(this);

    ///////////////////////////////////////////////
    // Spinner for Selecting the end sample
    ///////////////////////////////////////////////
    Spinner spinnerStatSampleEnd = (Spinner) findViewById(R.id.spinnerStatSampleEnd);
    m_spinnerToAdapter = new ReferencesAdapter(this, R.layout.bbs_spinner_layout); //android.R.layout.simple_spinner_item);
    m_spinnerToAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item); //android.R.layout.simple_spinner_dropdown_item);

    spinnerStatSampleEnd.setVisibility(View.VISIBLE);
    spinnerStatSampleEnd.setAdapter(m_spinnerToAdapter);
    // setSelection must be called after setAdapter
    if ((m_refToName != null) && !m_refToName.equals("")) {
        int pos = m_spinnerToAdapter.getPosition(m_refToName);
        spinnerStatSampleEnd.setSelection(pos);

    } else {
        spinnerStatSampleEnd.setSelection(m_spinnerToAdapter.getPosition(Reference.CURRENT_REF_FILENAME));
    }

    spinnerStatSampleEnd.setOnItemSelectedListener(this);

    ///////////////////////////////////////////////
    // sorting
    ///////////////////////////////////////////////
    m_iSorting = 0;

    // log reference store
    ReferenceStore.logReferences(this);

    if (LogSettings.DEBUG) {
        Log.i(TAG, "onCreate final state: refFrom=" + m_refFromName + " refTo=" + m_refToName);
        Log.i(TAG, "OnCreated end");
    }

}

From source file:es.usc.citius.servando.calendula.fragments.ScheduleImportFragment.java

void updateRoutineSelectionAdapter(final View entryView, Spinner routineSpinner, String[] routineNames) {
    ArrayAdapter<String> routineAdapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_spinner_item, routineNames);
    routineAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
    routineSpinner.setAdapter(routineAdapter);
}

From source file:com.ezac.gliderlogs.FlightDetailActivity.java

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.start_edit);
    // get references to our objects
    mDateText = (EditText) findViewById(R.id.flight_date);
    mRegiSpin = (Spinner) findViewById(R.id.flight_registration);
    mPilotSpin = (Spinner) findViewById(R.id.flight_pilot);
    mInstChck = (CheckBox) findViewById(R.id.flight_instruction);
    mCoPilotSpin = (Spinner) findViewById(R.id.flight_copilot);
    mStartText = (EditText) findViewById(R.id.flight_start);
    mLandText = (EditText) findViewById(R.id.flight_landing);
    mDuraText = (EditText) findViewById(R.id.flight_duration);
    // disable input, these are output only
    mDateText.setClickable(false);//from   ww w  . j av  a2s . co m
    mDateText.setFocusable(false);
    mStartText.setClickable(false);
    mStartText.setFocusable(false);
    mLandText.setClickable(false);
    mLandText.setFocusable(false);
    mDuraText.setClickable(false);
    mDuraText.setFocusable(false);
    mBodyText = (EditText) findViewById(R.id.flight_edit_notes);
    mDateText.setText(FlightOverviewActivity.ToDay);
    mTypeNorm = (CheckBox) findViewById(R.id.flight_type_norm);
    mTypePass = (CheckBox) findViewById(R.id.flight_type_pass);
    mTypeDona = (CheckBox) findViewById(R.id.flight_type_dona);
    mTypeClub = (CheckBox) findViewById(R.id.flight_type_club);

    mLaunchWinch = (CheckBox) findViewById(R.id.flight_launch_winch);
    mLaunchTow = (CheckBox) findViewById(R.id.flight_launch_tow);
    mLaunchMotor = (CheckBox) findViewById(R.id.flight_launch_motor);

    Button confirmButton = (Button) findViewById(R.id.flight_edit_button);
    Button exitButton = (Button) findViewById(R.id.flight_quit_button);
    Button againButton = (Button) findViewById(R.id.flight_again_button);
    Button timeSButton = (Button) findViewById(R.id.btnChangeSTime);
    Button timeLButton = (Button) findViewById(R.id.btnChangeLTime);
    Button clearSButton = (Button) findViewById(R.id.btnClearSTime);
    Button clearLButton = (Button) findViewById(R.id.btnClearLTime);
    Button gliderButton = (Button) findViewById(R.id.btn_ext_1);
    Button pilotButton = (Button) findViewById(R.id.btn_ext_2);
    Bundle extras = getIntent().getExtras();

    // get data from DB tables and load our glider/member list
    addItemSpinner1();
    addItemSpinner2();
    // only now check if these are still empty
    if (GliderList.isEmpty() || MemberList.isEmpty()) {
        makeToast("Opties -> Voer eerst de actie 'Dag opstarten' uit, mogelijk was er een netwerk probleem !.");
        setResult(RESULT_CANCELED);
        finish();
    }
    // check from the saved Instance
    flightUri = (bundle == null) ? null : (Uri) bundle.getParcelable(FlightsContentProvider.CONTENT_ITEM_TYPE);
    // Or passed from the other activity
    if (extras != null) {
        flightUri = extras.getParcelable(FlightsContentProvider.CONTENT_ITEM_TYPE);
        fillData(flightUri);
    }
    // bewaar ingevoerde informatie
    confirmButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mPilotSpin.getSelectedItem().equals(mCoPilotSpin.getSelectedItem())) {
                makeToast("'Gezagvoerder' en 'Co-Piloot' kunnen niet het zelfde zijn !!");
            } else {
                if (TextUtils.isEmpty((String) mRegiSpin.getSelectedItem())) {
                    makeToast("Verplichte velden invullen aub");
                } else {
                    setResult(RESULT_OK);
                    finish();
                }
            }
        }
    });
    // dupliceer de geselecteerde vlucht
    againButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            new AlertDialog.Builder(FlightDetailActivity.this).setTitle("Bevestig deze opdracht")
                    .setMessage("Wilt u deze vlucht dupliceren ? ")
                    .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int whichButton) {
                            // put some caheck in place as t avoid bogus record to be created
                            if ((!mDateText.getText().toString().equals(""))
                                    && (!mStartText.getText().toString().equals(""))
                                    && (!mLandText.getText().toString().equals(""))
                                    && (!mRegiSpin.getSelectedItem().equals(""))
                                    && (!mPilotSpin.getSelectedItem().equals(""))) {
                                ContentValues values = new ContentValues();
                                values.put(GliderLogTables.F_DATE, mDateText.getText().toString());
                                values.put(GliderLogTables.F_REGISTRATION,
                                        (String) mRegiSpin.getSelectedItem());
                                String ftype = "";
                                if (mTypeNorm.isChecked()) {
                                    ftype = "";
                                }
                                if (mTypePass.isChecked()) {
                                    ftype = "PASS";
                                }
                                if (mTypeDona.isChecked()) {
                                    ftype = "DONA";
                                }
                                if (mTypeClub.isChecked()) {
                                    ftype = "CLUB";
                                }
                                values.put(GliderLogTables.F_TYPE, ftype);
                                values.put(GliderLogTables.F_INSTRUCTION, (mInstChck.isChecked()) ? "J" : "N");
                                String fPilo = (String) mPilotSpin.getSelectedItem();
                                values.put(GliderLogTables.F_PILOT, fPilo);
                                String fPilo_id = "";
                                for (int i = 0; i < mPilotSpin.getCount(); i++) {
                                    String s = (String) mPilotSpin.getItemAtPosition(i);
                                    if (s.equalsIgnoreCase(fPilo)) {
                                        fPilo_id = MemberIndexList.get(i);
                                    }
                                }
                                values.put(GliderLogTables.F_PILOT_ID, fPilo_id);
                                String fCoPi = (String) mCoPilotSpin.getSelectedItem();
                                values.put(GliderLogTables.F_COPILOT, fCoPi);
                                String fCoPi_id = "";
                                for (int i = 0; i < mCoPilotSpin.getCount(); i++) {
                                    String s = (String) mCoPilotSpin.getItemAtPosition(i);
                                    if (s.equalsIgnoreCase(fCoPi)) {
                                        fCoPi_id = MemberIndexList.get(i);
                                    }
                                }
                                values.put(GliderLogTables.F_COPILOT_ID, fCoPi_id);
                                values.put(GliderLogTables.F_STARTED, "");
                                values.put(GliderLogTables.F_LANDED, "");
                                values.put(GliderLogTables.F_DURATION, "");
                                String fLaun = "";
                                if (mLaunchWinch.isChecked()) {
                                    fLaun = "L";
                                }
                                if (mLaunchTow.isChecked()) {
                                    fLaun = "S";
                                }
                                if (mLaunchMotor.isChecked()) {
                                    fLaun = "M";
                                }
                                values.put(GliderLogTables.F_LAUNCH, fLaun);
                                values.put(GliderLogTables.F_SENT, "0");
                                values.put(GliderLogTables.F_ACK, "0");
                                values.put(GliderLogTables.F_NOTES, "");
                                // New flight
                                flightUri = getContentResolver()
                                        .insert(FlightsContentProvider.CONTENT_URI_FLIGHT, values);
                            }
                        }
                    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int whichButton) {
                            // Do nothing.
                        }
                    }).show();
        }
    });

    exitButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            flg_save = true;
            setResult(RESULT_CANCELED);
            finish();
        }
    });

    timeSButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            time_mde = 10;
            // Creating a bundle object to pass currently set time to the fragment
            Bundle b = new Bundle();
            if (!mStartText.getText().toString().isEmpty()) {
                String[] split = mStartText.getText().toString().split(":");
                hour = Integer.parseInt(split[0]);
                minute = Integer.parseInt(split[1]);
            } else {
                final Calendar c = Calendar.getInstance();
                hour = c.get(Calendar.HOUR_OF_DAY);
                minute = c.get(Calendar.MINUTE);
            }
            b.putInt("set_hour", hour);
            b.putInt("set_minute", minute);
            // Instantiating TimePickerDialogFragment & pass it' arguments
            TimePickerDialogFragment timePicker = new TimePickerDialogFragment(mHandler);
            timePicker.setArguments(b);
            // Getting fragment manger for this activity & start transaction
            FragmentManager fm = getSupportFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            ft.add(timePicker, "time_picker");
            /** Opening the TimePicker fragment */
            ft.commit();
        }
    });

    timeLButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            time_mde = 20;
            // Creating a bundle object to pass currently set time to the fragment
            Bundle b = new Bundle();
            if (!mLandText.getText().toString().isEmpty()) {
                String[] split = mLandText.getText().toString().split(":");
                hour = Integer.parseInt(split[0]);
                minute = Integer.parseInt(split[1]);
            } else {
                final Calendar c = Calendar.getInstance();
                hour = c.get(Calendar.HOUR_OF_DAY);
                minute = c.get(Calendar.MINUTE);
            }
            b.putInt("set_hour", hour);
            b.putInt("set_minute", minute);
            // Instantiating TimePickerDialogFragment & pass it' arguments
            TimePickerDialogFragment timePicker = new TimePickerDialogFragment(mHandler);
            timePicker.setArguments(b);
            // Getting fragment manger for this activity & start transaction
            FragmentManager fm = getSupportFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            ft.add(timePicker, "time_picker");
            /** Opening the TimePicker fragment */
            ft.commit();
        }
    });

    clearSButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String S_T = mStartText.getText().toString();
            if (S_T.isEmpty()) {
                final Calendar c = Calendar.getInstance();
                //second = c.get(Calendar.SECOND);
                //mStartText.setText(Common.TwoDigits(c.get(Calendar.HOUR_OF_DAY)) + ":" + Common.TwoDigits(c.get(Calendar.MINUTE)));
                mStartText.setText(new StringBuilder().append(Common.TwoDigits(c.get(Calendar.HOUR_OF_DAY)))
                        .append(":").append(Common.TwoDigits(c.get(Calendar.MINUTE))));
            } else {
                mStartText.setText("");
            }
        }
    });

    clearLButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String L_T = mLandText.getText().toString();
            if (L_T.isEmpty()) {
                final Calendar c = Calendar.getInstance();
                //second = c.get(Calendar.SECOND);
                //mLandText.setText(Common.TwoDigits(c.get(Calendar.HOUR_OF_DAY)) + ":" + Common.TwoDigits(c.get(Calendar.MINUTE)));
                mLandText.setText(new StringBuilder().append(Common.TwoDigits(c.get(Calendar.HOUR_OF_DAY)))
                        .append(":").append(Common.TwoDigits(c.get(Calendar.MINUTE))));
            } else {
                mLandText.setText("");
            }
        }
    });

    mRegiSpin.setOnItemSelectedListener(new Custom0_OnItemSelectedListener());
    mPilotSpin.setOnItemSelectedListener(new Custom1_OnItemSelectedListener());

    gliderButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // get add_glider.xml view
            LayoutInflater li = LayoutInflater.from(edi_con);
            View promptsView = li.inflate(R.layout.add_glider, null);
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(edi_con);
            // set add_glider.xml to alertdialog builder
            alertDialogBuilder.setView(promptsView);
            final EditText userInput1 = (EditText) promptsView.findViewById(R.id.editTextInput1);
            final EditText userInput2 = (EditText) promptsView.findViewById(R.id.editTextInput2);
            final CheckBox userInput3 = (CheckBox) promptsView.findViewById(R.id.editCheckInput3);
            final CheckBox userInput4 = (CheckBox) promptsView.findViewById(R.id.editCheckInput4);
            // set dialog message
            alertDialogBuilder.setCancelable(false)
                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        @SuppressLint("DefaultLocale")
                        public void onClick(DialogInterface dialog, int id) {
                            // user input, convert to UC, add to glider list & spinner
                            result = userInput1.getText().toString().toUpperCase();
                            if (GliderList.contains(result)) {
                                makeToast("Invoer extra, deze kist bestaat reeds !");
                                result = null;
                                dialog.cancel();
                            } else {
                                GliderList.add(result);
                                GliderCall.add(userInput2.getText().toString().toUpperCase());
                                GliderSeatsList.add(userInput3.isChecked() ? "2" : "1");
                                GliderPrivateList.add(userInput4.isChecked() ? "1" : "0");
                                ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(
                                        FlightDetailActivity.this, android.R.layout.simple_spinner_item,
                                        GliderList);
                                dataAdapter
                                        .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                                mRegiSpin.setAdapter(dataAdapter);
                                // add to DB table
                                try {
                                    ContentValues values = new ContentValues();
                                    values.put(GliderLogTables.G_REGISTRATION, result);
                                    getContentResolver().insert(FlightsContentProvider.CONTENT_URI_GLIDER,
                                            values);
                                    values = null;
                                } catch (Exception e) {
                                    Log.e("Exception", "Error: " + e.toString());
                                }
                            }
                        }
                    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            result = null;
                            dialog.cancel();
                        }
                    });
            // create alert dialog & show it
            AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }
    });

    pilotButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // get prompts.xml view
            LayoutInflater li = LayoutInflater.from(edi_con);
            View promptsView = li.inflate(R.layout.add_member, null);
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(edi_con);
            // set prompts.xml to alertdialog builder
            alertDialogBuilder.setView(promptsView);
            final EditText userInput = (EditText) promptsView.findViewById(R.id.editTextDialogUserInput);
            // set dialog message
            alertDialogBuilder.setCancelable(false)
                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        @SuppressLint("DefaultLocale")
                        public void onClick(DialogInterface dialog, int id) {
                            // get user input check for at least 2
                            // parts
                            result = userInput.getText().toString();
                            if (MemberList.contains(result)) {
                                makeToast("Invoer extra, deze naam bestaat reeds !");
                                result = null;
                                dialog.cancel();
                            } else {
                                String[] name = result.split(" ");
                                if (name.length < 2) {
                                    makeToast(
                                            "Invoer extra, formaat => Voornaam (tussenvoegsel(s)) Achternaam is vereist !");
                                    result = null;
                                    dialog.cancel();
                                }
                                // add to member list & spinners
                                MemberList.add(result);
                                MemberIndexList.add("" + ini_id);
                                MemberInstrList.add("0");
                                ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(
                                        FlightDetailActivity.this, android.R.layout.simple_spinner_item,
                                        MemberList);
                                dataAdapter
                                        .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                                mPilotSpin.setAdapter(dataAdapter);
                                mCoPilotSpin.setAdapter(dataAdapter);
                                // add parts to DB table fields
                                AddNewMember(name);
                            }
                        }
                    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            result = null;
                            dialog.cancel();
                        }
                    });
            // create alert dialog & show it
            AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }
    });

    setMode();
}