Example usage for android.widget LinearLayout findViewById

List of usage examples for android.widget LinearLayout findViewById

Introduction

In this page you can find the example usage for android.widget LinearLayout findViewById.

Prototype

@Nullable
public final <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID, the view itself if the ID matches #getId() , or null if the ID is invalid (< 0) or there is no matching view in the hierarchy.

Usage

From source file:tm.alashow.datmusic.ui.activity.MainActivity.java

public void playAudio(final Audio audio) {
    final LinearLayout rootView = new LinearLayout(this);
    ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(this,
            R.style.Base_Theme_AppCompat_Light_Dialog);
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(contextThemeWrapper);
    alertDialogBuilder.setView(rootView);
    alertDialogBuilder.setNegativeButton(R.string.audio_player_close, null);

    final AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.setCanceledOnTouchOutside(false);

    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override//from  w ww  .j a  v a  2  s. co m
        public void onShow(DialogInterface dialog) {
            //change flat button color
            alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE)
                    .setTextColor(getResources().getColor(R.color.primary));
        }
    });
    //destroy mediaPlayer when dialog dismissed
    alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            resetPlayer();
        }
    });

    new PrepareAudioTask(rootView, new OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mediaPlayer, AudioWife audioWife) {
            mMediaPlayer = mediaPlayer;
            alertDialog.show();
            TextView nameView = (TextView) rootView.findViewById(R.id.name);
            if (nameView != null) {
                nameView.setText(audio.getArtist() + " - " + audio.getTitle());
            }
            audioWife.play();
        }

        @Override
        public void onError(Exception e) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    U.showCenteredToast(MainActivity.this, R.string.exception);
                }
            });
        }
    }).execute(Uri.parse(audio.getStreamUrl()));
}

From source file:com.mantz_it.rfanalyzer.MainActivity.java

/**
 * Will pop up a dialog to let the user adjust gain settings
 *//*from w  w  w .java2 s .  c om*/
private void adjustGain() {
    if (source == null)
        return;

    int sourceType = Integer.valueOf(preferences.getString(getString(R.string.pref_sourceType), "1"));
    switch (sourceType) {
    case FILE_SOURCE:
        Toast.makeText(this, getString(R.string.filesource_doesnt_support_gain), Toast.LENGTH_LONG).show();
        break;
    case HACKRF_SOURCE:
        // Prepare layout:
        final LinearLayout view_hackrf = (LinearLayout) this.getLayoutInflater().inflate(R.layout.hackrf_gain,
                null);
        final SeekBar sb_hackrf_vga = (SeekBar) view_hackrf.findViewById(R.id.sb_hackrf_vga_gain);
        final SeekBar sb_hackrf_lna = (SeekBar) view_hackrf.findViewById(R.id.sb_hackrf_lna_gain);
        final TextView tv_hackrf_vga = (TextView) view_hackrf.findViewById(R.id.tv_hackrf_vga_gain);
        final TextView tv_hackrf_lna = (TextView) view_hackrf.findViewById(R.id.tv_hackrf_lna_gain);
        sb_hackrf_vga.setMax(HackrfSource.MAX_VGA_RX_GAIN / HackrfSource.VGA_RX_GAIN_STEP_SIZE);
        sb_hackrf_lna.setMax(HackrfSource.MAX_LNA_GAIN / HackrfSource.LNA_GAIN_STEP_SIZE);
        sb_hackrf_vga.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                tv_hackrf_vga.setText("" + progress * HackrfSource.VGA_RX_GAIN_STEP_SIZE);
                ((HackrfSource) source).setVgaRxGain(progress * HackrfSource.VGA_RX_GAIN_STEP_SIZE);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        sb_hackrf_lna.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                tv_hackrf_lna.setText("" + progress * HackrfSource.LNA_GAIN_STEP_SIZE);
                ((HackrfSource) source).setLnaGain(progress * HackrfSource.LNA_GAIN_STEP_SIZE);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        sb_hackrf_vga.setProgress(((HackrfSource) source).getVgaRxGain() / HackrfSource.VGA_RX_GAIN_STEP_SIZE);
        sb_hackrf_lna.setProgress(((HackrfSource) source).getLnaGain() / HackrfSource.LNA_GAIN_STEP_SIZE);

        // Show dialog:
        AlertDialog hackrfDialog = new AlertDialog.Builder(this).setTitle("Adjust Gain Settings")
                .setView(view_hackrf).setPositiveButton("Set", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // safe preferences:
                        SharedPreferences.Editor edit = preferences.edit();
                        edit.putInt(getString(R.string.pref_hackrf_vgaRxGain),
                                sb_hackrf_vga.getProgress() * HackrfSource.VGA_RX_GAIN_STEP_SIZE);
                        edit.putInt(getString(R.string.pref_hackrf_lnaGain),
                                sb_hackrf_lna.getProgress() * HackrfSource.LNA_GAIN_STEP_SIZE);
                        edit.apply();
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // do nothing
                    }
                }).create();
        hackrfDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                // sync source with (new/old) settings
                int vgaRxGain = preferences.getInt(getString(R.string.pref_hackrf_vgaRxGain),
                        HackrfSource.MAX_VGA_RX_GAIN / 2);
                int lnaGain = preferences.getInt(getString(R.string.pref_hackrf_lnaGain),
                        HackrfSource.MAX_LNA_GAIN / 2);
                if (((HackrfSource) source).getVgaRxGain() != vgaRxGain)
                    ((HackrfSource) source).setVgaRxGain(vgaRxGain);
                if (((HackrfSource) source).getLnaGain() != lnaGain)
                    ((HackrfSource) source).setLnaGain(lnaGain);
            }
        });
        hackrfDialog.show();
        hackrfDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        break;
    case RTLSDR_SOURCE:
        final int[] possibleGainValues = ((RtlsdrSource) source).getPossibleGainValues();
        final int[] possibleIFGainValues = ((RtlsdrSource) source).getPossibleIFGainValues();
        if (possibleGainValues.length <= 1 && possibleIFGainValues.length <= 1) {
            Toast.makeText(MainActivity.this, source.getName() + " does not support gain adjustment!",
                    Toast.LENGTH_LONG).show();
        }
        // Prepare layout:
        final LinearLayout view_rtlsdr = (LinearLayout) this.getLayoutInflater().inflate(R.layout.rtlsdr_gain,
                null);
        final LinearLayout ll_rtlsdr_gain = (LinearLayout) view_rtlsdr.findViewById(R.id.ll_rtlsdr_gain);
        final LinearLayout ll_rtlsdr_ifgain = (LinearLayout) view_rtlsdr.findViewById(R.id.ll_rtlsdr_ifgain);
        final Switch sw_rtlsdr_manual_gain = (Switch) view_rtlsdr.findViewById(R.id.sw_rtlsdr_manual_gain);
        final CheckBox cb_rtlsdr_agc = (CheckBox) view_rtlsdr.findViewById(R.id.cb_rtlsdr_agc);
        final SeekBar sb_rtlsdr_gain = (SeekBar) view_rtlsdr.findViewById(R.id.sb_rtlsdr_gain);
        final SeekBar sb_rtlsdr_ifGain = (SeekBar) view_rtlsdr.findViewById(R.id.sb_rtlsdr_ifgain);
        final TextView tv_rtlsdr_gain = (TextView) view_rtlsdr.findViewById(R.id.tv_rtlsdr_gain);
        final TextView tv_rtlsdr_ifGain = (TextView) view_rtlsdr.findViewById(R.id.tv_rtlsdr_ifgain);

        // Assign current gain:
        int gainIndex = 0;
        int ifGainIndex = 0;
        for (int i = 0; i < possibleGainValues.length; i++) {
            if (((RtlsdrSource) source).getGain() == possibleGainValues[i]) {
                gainIndex = i;
                break;
            }
        }
        for (int i = 0; i < possibleIFGainValues.length; i++) {
            if (((RtlsdrSource) source).getIFGain() == possibleIFGainValues[i]) {
                ifGainIndex = i;
                break;
            }
        }
        sb_rtlsdr_gain.setMax(possibleGainValues.length - 1);
        sb_rtlsdr_ifGain.setMax(possibleIFGainValues.length - 1);
        sb_rtlsdr_gain.setProgress(gainIndex);
        sb_rtlsdr_ifGain.setProgress(ifGainIndex);
        tv_rtlsdr_gain.setText("" + possibleGainValues[gainIndex]);
        tv_rtlsdr_ifGain.setText("" + possibleIFGainValues[ifGainIndex]);

        // Assign current manual gain and agc setting
        sw_rtlsdr_manual_gain.setChecked(((RtlsdrSource) source).isManualGain());
        cb_rtlsdr_agc.setChecked(((RtlsdrSource) source).isAutomaticGainControl());

        // Add listener to gui elements:
        sw_rtlsdr_manual_gain.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                sb_rtlsdr_gain.setEnabled(isChecked);
                tv_rtlsdr_gain.setEnabled(isChecked);
                sb_rtlsdr_ifGain.setEnabled(isChecked);
                tv_rtlsdr_ifGain.setEnabled(isChecked);
                ((RtlsdrSource) source).setManualGain(isChecked);
                if (isChecked) {
                    ((RtlsdrSource) source).setGain(possibleGainValues[sb_rtlsdr_gain.getProgress()]);
                    ((RtlsdrSource) source).setIFGain(possibleIFGainValues[sb_rtlsdr_ifGain.getProgress()]);
                }
            }
        });
        cb_rtlsdr_agc.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                ((RtlsdrSource) source).setAutomaticGainControl(isChecked);
            }
        });
        sb_rtlsdr_gain.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                tv_rtlsdr_gain.setText("" + possibleGainValues[progress]);
                ((RtlsdrSource) source).setGain(possibleGainValues[progress]);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        sb_rtlsdr_ifGain.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                tv_rtlsdr_ifGain.setText("" + possibleIFGainValues[progress]);
                ((RtlsdrSource) source).setIFGain(possibleIFGainValues[progress]);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });

        // Disable gui elements if gain cannot be adjusted:
        if (possibleGainValues.length <= 1)
            ll_rtlsdr_gain.setVisibility(View.GONE);
        if (possibleIFGainValues.length <= 1)
            ll_rtlsdr_ifgain.setVisibility(View.GONE);

        if (!sw_rtlsdr_manual_gain.isChecked()) {
            sb_rtlsdr_gain.setEnabled(false);
            tv_rtlsdr_gain.setEnabled(false);
            sb_rtlsdr_ifGain.setEnabled(false);
            tv_rtlsdr_ifGain.setEnabled(false);
        }

        // Show dialog:
        AlertDialog rtlsdrDialog = new AlertDialog.Builder(this).setTitle("Adjust Gain Settings")
                .setView(view_rtlsdr).setPositiveButton("Set", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // safe preferences:
                        SharedPreferences.Editor edit = preferences.edit();
                        edit.putBoolean(getString(R.string.pref_rtlsdr_manual_gain),
                                sw_rtlsdr_manual_gain.isChecked());
                        edit.putBoolean(getString(R.string.pref_rtlsdr_agc), cb_rtlsdr_agc.isChecked());
                        edit.putInt(getString(R.string.pref_rtlsdr_gain),
                                possibleGainValues[sb_rtlsdr_gain.getProgress()]);
                        edit.putInt(getString(R.string.pref_rtlsdr_ifGain),
                                possibleIFGainValues[sb_rtlsdr_ifGain.getProgress()]);
                        edit.apply();
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // do nothing
                    }
                }).create();
        rtlsdrDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                boolean manualGain = preferences.getBoolean(getString(R.string.pref_rtlsdr_manual_gain), false);
                boolean agc = preferences.getBoolean(getString(R.string.pref_rtlsdr_agc), false);
                int gain = preferences.getInt(getString(R.string.pref_rtlsdr_gain), 0);
                int ifGain = preferences.getInt(getString(R.string.pref_rtlsdr_ifGain), 0);
                ((RtlsdrSource) source).setGain(gain);
                ((RtlsdrSource) source).setIFGain(ifGain);
                ((RtlsdrSource) source).setManualGain(manualGain);
                ((RtlsdrSource) source).setAutomaticGainControl(agc);
                if (manualGain) {
                    // Note: This is a workaround. After setting manual gain to true we must
                    // rewrite the manual gain values:
                    ((RtlsdrSource) source).setGain(gain);
                    ((RtlsdrSource) source).setIFGain(ifGain);
                }
            }
        });
        rtlsdrDialog.show();
        rtlsdrDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        break;
    default:
        Log.e(LOGTAG, "adjustGain: Invalid source type: " + sourceType);
        break;
    }
}

From source file:co.taqat.call.CallActivity.java

private void displayPausedCalls(Resources resources, final LinphoneCall call, int index) {
    // Control Row
    LinearLayout callView;

    if (call == null) {
        callView = (LinearLayout) inflater.inflate(R.layout.conference_paused_row, container, false);
        callView.setId(index + 1);//w w  w . j a  v  a2 s  .  c om
        callView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                pauseOrResumeConference();
            }
        });
    } else {
        callView = (LinearLayout) inflater.inflate(R.layout.call_inactive_row, container, false);
        callView.setId(index + 1);

        TextView contactName = (TextView) callView.findViewById(R.id.contact_name);
        ImageView contactImage = (ImageView) callView.findViewById(R.id.contact_picture);

        LinphoneAddress lAddress = call.getRemoteAddress();
        setContactInformation(contactName, contactImage, lAddress);
        displayCallStatusIconAndReturnCallPaused(callView, call);
        registerCallDurationTimer(callView, call);
    }
    callsList.addView(callView);
}

From source file:com.metinkale.prayerapp.vakit.fragments.NotificationPrefs.java

private void initCuma(int switchId, int textId, int expandId, final Vakit vakit) {
    final SwitchCompat sw = (SwitchCompat) mView.findViewById(switchId);
    final LinearLayout expand = (LinearLayout) mView.findViewById(expandId);

    sw.setChecked(mTimes.isCumaActive());
    sw.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override/*from   ww w .ja  v  a 2s  .  c  o  m*/
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            mTimes.setCumaActive(b);
            if (!b && expand.getVisibility() == View.VISIBLE) {
                expand.setVisibility(View.GONE);
            }

        }
    });

    View title = (View) mView.findViewById(textId).getParent();

    title.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            if (!BuildConfig.DEBUG) {
                return false;
            }
            mTestAlarm = true;
            Times.Alarm a = new Times.Alarm();
            a.time = System.currentTimeMillis() + (5 * 1000);
            a.city = mTimes.getID();
            a.cuma = true;
            a.vakit = vakit;
            AlarmReceiver.setAlarm(getActivity(), a);
            Toast.makeText(App.getContext(), "Will play within 5 seconds", Toast.LENGTH_LONG).show();
            return true;
        }
    });

    title.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (sw.isChecked()) {
                expand.setVisibility((expand.getVisibility() == View.VISIBLE) ? View.GONE : View.VISIBLE);
            } else {
                Toast.makeText(getActivity(), R.string.activateForMorePrefs, Toast.LENGTH_LONG).show();
            }
        }
    });

    PrefsView sound = (PrefsView) expand.findViewById(R.id.sound);
    sound.setPrefType(PrefsView.Pref.Sela);
    sound.setVakit(vakit);
    sound.setPrefFunctions(new PrefsView.PrefsFunctions() {
        @Override
        public Object getValue() {
            return mTimes.getCumaSound();
        }

        @Override
        public void setValue(Object obj) {
            mTimes.setCumaSound((String) obj);
        }
    });

    PrefsView vibr = (PrefsView) expand.findViewById(R.id.vibration);
    vibr.setPrefFunctions(new PrefsView.PrefsFunctions() {
        @Override
        public Object getValue() {
            return mTimes.hasCumaVibration();
        }

        @Override
        public void setValue(Object obj) {
            mTimes.setCumaVibration((boolean) obj);
        }
    });

    PrefsView silenter = (PrefsView) expand.findViewById(R.id.silenter);
    silenter.setPrefFunctions(new PrefsView.PrefsFunctions() {
        @Override
        public Object getValue() {
            return mTimes.getCumaSilenterDuration();
        }

        @Override
        public void setValue(Object obj) {
            mTimes.setCumaSilenterDuration((int) obj);
        }
    });

    PrefsView dua = (PrefsView) expand.findViewById(R.id.dua);
    dua.setVisibility(View.GONE);

    PrefsView time = (PrefsView) expand.findViewById(R.id.time);
    time.setPrefFunctions(new PrefsView.PrefsFunctions() {
        @Override
        public Object getValue() {
            return mTimes.getCumaTime();
        }

        @Override
        public void setValue(Object obj) {
            mTimes.setCumaTime((int) obj);
        }
    });
}

From source file:com.metinkale.prayerapp.vakit.fragments.NotificationPrefs.java

private void initMain(int switchId, int textId, int expandId, final Vakit vakit) {
    final SwitchCompat sw = (SwitchCompat) mView.findViewById(switchId);
    final LinearLayout expand = (LinearLayout) mView.findViewById(expandId);

    sw.setChecked(mTimes.isNotificationActive(vakit));
    sw.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override/* w ww . j av a  2s  .c  o m*/
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            mTimes.setNotificationActive(vakit, b);
            if (!b && expand.getVisibility() == View.VISIBLE) {
                expand.setVisibility(View.GONE);
            }

        }
    });

    View title = (View) mView.findViewById(textId).getParent();

    title.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            if (!BuildConfig.DEBUG) {
                return false;
            }
            mTestAlarm = true;
            Times.Alarm a = new Times.Alarm();
            a.time = System.currentTimeMillis() + (5 * 1000);
            a.city = mTimes.getID();
            a.vakit = vakit;
            AlarmReceiver.setAlarm(getActivity(), a);
            Toast.makeText(App.getContext(), "Will play within 5 seconds", Toast.LENGTH_LONG).show();
            return true;
        }
    });
    title.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (sw.isChecked()) {
                expand.setVisibility(expand.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
            } else {
                Toast.makeText(getActivity(), R.string.activateForMorePrefs, Toast.LENGTH_LONG).show();
            }
        }
    });

    PrefsView sound = (PrefsView) expand.findViewById(R.id.sound);
    sound.setVakit(vakit);
    sound.setPrefFunctions(new PrefsView.PrefsFunctions() {
        @Override
        public Object getValue() {
            return mTimes.getSound(vakit);
        }

        @Override
        public void setValue(Object obj) {
            mTimes.setSound(vakit, (String) obj);
        }
    });

    PrefsView vibr = (PrefsView) expand.findViewById(R.id.vibration);
    vibr.setPrefFunctions(new PrefsView.PrefsFunctions() {
        @Override
        public Object getValue() {
            return mTimes.hasVibration(vakit);
        }

        @Override
        public void setValue(Object obj) {
            mTimes.setVibration(vakit, (boolean) obj);
        }
    });

    PrefsView silenter = (PrefsView) expand.findViewById(R.id.silenter);
    silenter.setPrefFunctions(new PrefsView.PrefsFunctions() {
        @Override
        public Object getValue() {
            return mTimes.getSilenterDuration(vakit);
        }

        @Override
        public void setValue(Object obj) {
            mTimes.setSilenterDuration(vakit, (int) obj);
        }
    });

    PrefsView dua = (PrefsView) expand.findViewById(R.id.dua);
    dua.setPrefFunctions(new PrefsView.PrefsFunctions() {
        @Override
        public Object getValue() {
            return mTimes.getDua(vakit);
        }

        @Override
        public void setValue(Object obj) {
            mTimes.setDua(vakit, (String) obj);
        }
    });

    PrefsView time = (PrefsView) expand.findViewById(R.id.time);
    if (vakit == Vakit.SABAH) {
        time.setTag("SabahTime");
        time.setPrefFunctions(new PrefsView.PrefsFunctions() {
            @Override
            public Object getValue() {
                return mTimes.getSabahTime() * (mTimes.isAfterImsak() ? -1 : 1);
            }

            @Override
            public void setValue(Object obj) {
                int time = (int) obj;
                mTimes.setSabahTime(Math.abs(time));
                mTimes.setAfterImsak(time < 0);
            }
        });
    } else {
        time.setVisibility(View.GONE);
    }
}

From source file:com.metinkale.prayerapp.vakit.fragments.NotificationPrefs.java

private void initEarly(int switchId, int textId, int expandId, final Vakit vakit) {
    final SwitchCompat sw = (SwitchCompat) mView.findViewById(switchId);
    final LinearLayout expand = (LinearLayout) mView.findViewById(expandId);

    sw.setChecked(mTimes.isEarlyNotificationActive(vakit));

    sw.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override/*from  w w w .  j a  v  a2 s  .c  o  m*/
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            mTimes.setEarlyNotificationActive(vakit, b);
            if (!b && expand.getVisibility() == View.VISIBLE) {
                expand.setVisibility(View.GONE);
            }

        }
    });

    View title = (View) mView.findViewById(textId).getParent();

    title.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            if (!BuildConfig.DEBUG) {
                return false;
            }
            mTestAlarm = true;
            Times.Alarm a = new Times.Alarm();
            a.time = System.currentTimeMillis() + (5 * 1000);
            a.city = mTimes.getID();
            a.early = true;
            a.vakit = vakit;
            AlarmReceiver.setAlarm(getActivity(), a);
            Toast.makeText(App.getContext(), "Will play within 5 seconds", Toast.LENGTH_LONG).show();
            return true;
        }
    });
    title.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (sw.isChecked()) {
                expand.setVisibility((expand.getVisibility() == View.VISIBLE) ? View.GONE : View.VISIBLE);
            } else {
                Toast.makeText(getActivity(), R.string.activateForMorePrefs, Toast.LENGTH_LONG).show();
            }
        }
    });

    PrefsView sound = (PrefsView) expand.findViewById(R.id.sound);
    sound.setVakit(vakit);
    sound.setPrefFunctions(new PrefsView.PrefsFunctions() {
        @Override
        public Object getValue() {
            return mTimes.getEarlySound(vakit);
        }

        @Override
        public void setValue(Object obj) {
            mTimes.setEarlySound(vakit, (String) obj);
        }
    });

    PrefsView vibr = (PrefsView) expand.findViewById(R.id.vibration);
    vibr.setPrefFunctions(new PrefsView.PrefsFunctions() {
        @Override
        public Object getValue() {
            return mTimes.hasEarlyVibration(vakit);
        }

        @Override
        public void setValue(Object obj) {
            mTimes.setEarlyVibration(vakit, (boolean) obj);
        }
    });

    PrefsView silenter = (PrefsView) expand.findViewById(R.id.silenter);
    silenter.setPrefFunctions(new PrefsView.PrefsFunctions() {
        @Override
        public Object getValue() {
            return mTimes.getEarlySilenterDuration(vakit);
        }

        @Override
        public void setValue(Object obj) {
            mTimes.setEarlySilenterDuration(vakit, (int) obj);
        }
    });

    PrefsView dua = (PrefsView) expand.findViewById(R.id.dua);
    dua.setVisibility(View.GONE);

    PrefsView time = (PrefsView) expand.findViewById(R.id.time);
    time.setPrefFunctions(new PrefsView.PrefsFunctions() {
        @Override
        public Object getValue() {
            return mTimes.getEarlyTime(vakit);
        }

        @Override
        public void setValue(Object obj) {
            mTimes.setEarlyTime(vakit, (int) obj);
        }
    });

}

From source file:com.farmerbb.taskbar.service.StartMenuService.java

@SuppressLint("RtlHardcoded")
private void drawStartMenu() {
    IconCache.getInstance(this).clearCache();

    final SharedPreferences pref = U.getSharedPreferences(this);
    final boolean hasHardwareKeyboard = getResources()
            .getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS;

    switch (pref.getString("show_search_bar", "keyboard")) {
    case "always":
        shouldShowSearchBox = true;/*  www  . ja  v a2s.  co m*/
        break;
    case "keyboard":
        shouldShowSearchBox = hasHardwareKeyboard;
        break;
    case "never":
        shouldShowSearchBox = false;
        break;
    }

    // Initialize layout params
    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    U.setCachedRotation(windowManager.getDefaultDisplay().getRotation());

    final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            shouldShowSearchBox ? 0
                    : WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                            | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            PixelFormat.TRANSLUCENT);

    // Determine where to show the start menu on screen
    switch (U.getTaskbarPosition(this)) {
    case "bottom_left":
        layoutId = R.layout.start_menu_left;
        params.gravity = Gravity.BOTTOM | Gravity.LEFT;
        break;
    case "bottom_vertical_left":
        layoutId = R.layout.start_menu_vertical_left;
        params.gravity = Gravity.BOTTOM | Gravity.LEFT;
        break;
    case "bottom_right":
        layoutId = R.layout.start_menu_right;
        params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
        break;
    case "bottom_vertical_right":
        layoutId = R.layout.start_menu_vertical_right;
        params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
        break;
    case "top_left":
        layoutId = R.layout.start_menu_top_left;
        params.gravity = Gravity.TOP | Gravity.LEFT;
        break;
    case "top_vertical_left":
        layoutId = R.layout.start_menu_vertical_left;
        params.gravity = Gravity.TOP | Gravity.LEFT;
        break;
    case "top_right":
        layoutId = R.layout.start_menu_top_right;
        params.gravity = Gravity.TOP | Gravity.RIGHT;
        break;
    case "top_vertical_right":
        layoutId = R.layout.start_menu_vertical_right;
        params.gravity = Gravity.TOP | Gravity.RIGHT;
        break;
    }

    // Initialize views
    int theme = 0;

    switch (pref.getString("theme", "light")) {
    case "light":
        theme = R.style.AppTheme;
        break;
    case "dark":
        theme = R.style.AppTheme_Dark;
        break;
    }

    ContextThemeWrapper wrapper = new ContextThemeWrapper(this, theme);
    layout = (StartMenuLayout) LayoutInflater.from(wrapper).inflate(layoutId, null);
    startMenu = (GridView) layout.findViewById(R.id.start_menu);

    if ((shouldShowSearchBox && !hasHardwareKeyboard)
            || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
        layout.viewHandlesBackButton();

    boolean scrollbar = pref.getBoolean("scrollbar", false);
    startMenu.setFastScrollEnabled(scrollbar);
    startMenu.setFastScrollAlwaysVisible(scrollbar);
    startMenu.setScrollBarStyle(scrollbar ? View.SCROLLBARS_OUTSIDE_INSET : View.SCROLLBARS_INSIDE_OVERLAY);

    if (pref.getBoolean("transparent_start_menu", false))
        startMenu.setBackgroundColor(0);

    searchView = (SearchView) layout.findViewById(R.id.search);

    int backgroundTint = U.getBackgroundTint(this);

    FrameLayout startMenuFrame = (FrameLayout) layout.findViewById(R.id.start_menu_frame);
    FrameLayout searchViewLayout = (FrameLayout) layout.findViewById(R.id.search_view_layout);
    startMenuFrame.setBackgroundColor(backgroundTint);
    searchViewLayout.setBackgroundColor(backgroundTint);

    if (shouldShowSearchBox) {
        if (!hasHardwareKeyboard)
            searchView.setIconifiedByDefault(true);

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                if (!hasSubmittedQuery) {
                    ListAdapter adapter = startMenu.getAdapter();
                    if (adapter != null) {
                        hasSubmittedQuery = true;

                        if (adapter.getCount() > 0) {
                            View view = adapter.getView(0, null, startMenu);
                            LinearLayout layout = (LinearLayout) view.findViewById(R.id.entry);
                            layout.performClick();
                        } else {
                            if (pref.getBoolean("hide_taskbar", true)
                                    && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                                LocalBroadcastManager.getInstance(StartMenuService.this)
                                        .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_TASKBAR"));
                            else
                                LocalBroadcastManager.getInstance(StartMenuService.this)
                                        .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));

                            Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
                            intent.putExtra(SearchManager.QUERY, query);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            if (intent.resolveActivity(getPackageManager()) != null)
                                startActivity(intent);
                            else {
                                Uri uri = new Uri.Builder().scheme("https").authority("www.google.com")
                                        .path("search").appendQueryParameter("q", query).build();

                                intent = new Intent(Intent.ACTION_VIEW);
                                intent.setData(uri);
                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                                try {
                                    startActivity(intent);
                                } catch (ActivityNotFoundException e) {
                                    /* Gracefully fail */ }
                            }
                        }
                    }
                }
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                searchView.setIconified(false);

                View closeButton = searchView.findViewById(R.id.search_close_btn);
                if (closeButton != null)
                    closeButton.setVisibility(View.GONE);

                refreshApps(newText, false);

                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
                    new Handler().postDelayed(() -> {
                        EditText editText = (EditText) searchView.findViewById(R.id.search_src_text);
                        if (editText != null) {
                            editText.requestFocus();
                            editText.setSelection(editText.getText().length());
                        }
                    }, 50);
                }

                return true;
            }
        });

        searchView.setOnQueryTextFocusChangeListener((view, b) -> {
            if (!hasHardwareKeyboard) {
                ViewGroup.LayoutParams params1 = startMenu.getLayoutParams();
                params1.height = getResources().getDimensionPixelSize(b
                        && !U.isServiceRunning(this, "com.farmerbb.secondscreen.service.DisableKeyboardService")
                                ? R.dimen.start_menu_height_half
                                : R.dimen.start_menu_height);
                startMenu.setLayoutParams(params1);
            }

            if (!b) {
                if (hasHardwareKeyboard && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1)
                    LocalBroadcastManager.getInstance(StartMenuService.this)
                            .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
                else {
                    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                }
            }
        });

        searchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);

        LinearLayout powerButton = (LinearLayout) layout.findViewById(R.id.power_button);
        powerButton.setOnClickListener(view -> {
            int[] location = new int[2];
            view.getLocationOnScreen(location);
            openContextMenu(location);
        });

        powerButton.setOnGenericMotionListener((view, motionEvent) -> {
            if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS
                    && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
                int[] location = new int[2];
                view.getLocationOnScreen(location);
                openContextMenu(location);
            }
            return false;
        });

        searchViewLayout.setOnClickListener(view -> searchView.setIconified(false));

        startMenu.setOnItemClickListener((parent, view, position, id) -> {
            hideStartMenu();

            AppEntry entry = (AppEntry) parent.getAdapter().getItem(position);
            U.launchApp(StartMenuService.this, entry.getPackageName(), entry.getComponentName(),
                    entry.getUserId(StartMenuService.this), null, false, false);
        });

        if (pref.getBoolean("transparent_start_menu", false))
            layout.findViewById(R.id.search_view_child_layout).setBackgroundColor(0);
    } else
        searchViewLayout.setVisibility(View.GONE);

    textView = (TextView) layout.findViewById(R.id.no_apps_found);

    LocalBroadcastManager.getInstance(this).unregisterReceiver(toggleReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(toggleReceiverAlt);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(hideReceiver);

    LocalBroadcastManager.getInstance(this).registerReceiver(toggleReceiver,
            new IntentFilter("com.farmerbb.taskbar.TOGGLE_START_MENU"));
    LocalBroadcastManager.getInstance(this).registerReceiver(toggleReceiverAlt,
            new IntentFilter("com.farmerbb.taskbar.TOGGLE_START_MENU_ALT"));
    LocalBroadcastManager.getInstance(this).registerReceiver(hideReceiver,
            new IntentFilter("com.farmerbb.taskbar.HIDE_START_MENU"));

    handler = new Handler();
    refreshApps(true);

    windowManager.addView(layout, params);
}

From source file:com.aware.Aware_Preferences.java

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

    mSensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);

    //Start the Aware
    Intent startAware = new Intent(getApplicationContext(), Aware.class);
    startService(startAware);/* ww w  . j  a v a  2s. c o  m*/

    addPreferencesFromResource(R.xml.aware_preferences);
    setContentView(R.layout.aware_ui);

    navigationDrawer = (DrawerLayout) findViewById(R.id.aware_ui_main);
    navigationList = (ListView) findViewById(R.id.aware_navigation);
    navigationToggle = new ActionBarDrawerToggle(this, navigationDrawer, R.drawable.ic_drawer,
            R.string.drawer_open, R.string.drawer_close) {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (Build.VERSION.SDK_INT > 11) {
                getActionBar().setTitle(getTitle());
                invalidateOptionsMenu();
            }
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (Build.VERSION.SDK_INT > 11) {
                getActionBar().setTitle(getTitle());
                invalidateOptionsMenu();
            }
        }
    };

    navigationDrawer.setDrawerListener(navigationToggle);

    String[] options = { "Stream", "Sensors", "Plugins", "Studies" };
    NavigationAdapter nav_adapter = new NavigationAdapter(getApplicationContext(), options);
    navigationList.setAdapter(nav_adapter);
    navigationList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            LinearLayout item_container = (LinearLayout) view.findViewById(R.id.nav_container);
            item_container.setBackgroundColor(Color.DKGRAY);

            for (int i = 0; i < navigationList.getChildCount(); i++) {
                if (i != position) {
                    LinearLayout other = (LinearLayout) navigationList.getChildAt(i);
                    LinearLayout other_item = (LinearLayout) other.findViewById(R.id.nav_container);
                    other_item.setBackgroundColor(Color.TRANSPARENT);
                }
            }

            Bundle animations = ActivityOptions.makeCustomAnimation(Aware_Preferences.this,
                    R.anim.anim_slide_in_left, R.anim.anim_slide_out_left).toBundle();
            switch (position) {
            case 0: //Stream
                Intent stream_ui = new Intent(Aware_Preferences.this, Stream_UI.class);
                startActivity(stream_ui, animations);
                break;
            case 1: //Sensors
                Intent sensors_ui = new Intent(Aware_Preferences.this, Aware_Preferences.class);
                startActivity(sensors_ui, animations);
                break;
            case 2: //Plugins
                Intent plugin_manager = new Intent(Aware_Preferences.this, Plugins_Manager.class);
                startActivity(plugin_manager, animations);
                break;
            case 3: //Studies
                if (Aware.getSetting(getApplicationContext(), "study_id").length() > 0) {
                    new Async_StudyData().execute(
                            Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER));
                } else {
                    Intent join_study = new Intent(Aware_Preferences.this, CameraStudy.class);
                    startActivityForResult(join_study, REQUEST_JOIN_STUDY, animations);
                }
                break;
            }

            navigationDrawer.closeDrawer(navigationList);
        }
    });

    if (getActionBar() != null) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);
    }

    SharedPreferences prefs = getSharedPreferences(getPackageName(), Context.MODE_PRIVATE);
    if (prefs.getAll().isEmpty()
            && Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID).length() == 0) {
        is_first_time = true;
        PreferenceManager.setDefaultValues(getApplicationContext(), getPackageName(), Context.MODE_PRIVATE,
                R.xml.aware_preferences, true);
        prefs.edit().commit(); //commit changes
    } else {
        PreferenceManager.setDefaultValues(getApplicationContext(), getPackageName(), Context.MODE_PRIVATE,
                R.xml.aware_preferences, false);
    }

    Map<String, ?> defaults = prefs.getAll();
    for (Map.Entry<String, ?> entry : defaults.entrySet()) {
        if (Aware.getSetting(getApplicationContext(), entry.getKey()).length() == 0) {
            Aware.setSetting(getApplicationContext(), entry.getKey(), entry.getValue());
        }
    }

    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID).length() == 0) {
        UUID uuid = UUID.randomUUID();
        Aware.setSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID, uuid.toString());
    }
}

From source file:cm.aptoide.pt.MainActivity.java

private void loadUItopapps() {
    ((ToggleButton) featuredView.findViewById(R.id.toggleButton1)).setOnCheckedChangeListener(null);
    Cursor c = db.getFeaturedTopApps();

    values = new ArrayList<HashMap<String, String>>();
    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        HashMap<String, String> item = new HashMap<String, String>();
        item.put("name", c.getString(1));
        item.put("icon", db.getIconsPath(0, Category.TOPFEATURED) + c.getString(4));
        item.put("rating", c.getString(5));
        item.put("id", c.getString(0));
        item.put("apkid", c.getString(7));
        item.put("vercode", c.getString(8));
        item.put("vername", c.getString(2));
        item.put("downloads", c.getString(6));
        if (values.size() == 26) {
            break;
        }/*ww  w.  java  2s .  c  om*/
        values.add(item);
    }
    c.close();

    runOnUiThread(new Runnable() {

        public void run() {

            LinearLayout ll = (LinearLayout) featuredView.findViewById(R.id.container);
            ll.removeAllViews();
            LinearLayout llAlso = new LinearLayout(MainActivity.this);
            llAlso.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            llAlso.setOrientation(LinearLayout.HORIZONTAL);
            for (int i = 0; i != values.size(); i++) {
                LinearLayout txtSamItem = (LinearLayout) getLayoutInflater().inflate(R.layout.row_grid_item,
                        null);
                ((TextView) txtSamItem.findViewById(R.id.name)).setText(values.get(i).get("name"));
                // ((TextView) txtSamItem.findViewById(R.id.version))
                // .setText(getString(R.string.version) +" "+
                // values.get(i).get("vername"));
                ((TextView) txtSamItem.findViewById(R.id.downloads)).setText(
                        "(" + values.get(i).get("downloads") + " " + getString(R.string.downloads) + ")");
                String hashCode = (values.get(i).get("apkid") + "|" + values.get(i).get("vercode")) + "";
                cm.aptoide.com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(
                        values.get(i).get("icon"), (ImageView) txtSamItem.findViewById(R.id.icon), hashCode);

                // imageLoader.DisplayImage(-1, values.get(i).get("icon"),
                // (ImageView) txtSamItem.findViewById(R.id.icon),
                // mContext);
                float stars = 0f;
                try {
                    stars = Float.parseFloat(values.get(i).get("rating"));
                } catch (Exception e) {
                    stars = 0f;
                }
                ((RatingBar) txtSamItem.findViewById(R.id.rating)).setRating(stars);
                ((RatingBar) txtSamItem.findViewById(R.id.rating)).setIsIndicator(true);
                txtSamItem.setPadding(10, 0, 0, 0);
                txtSamItem.setTag(values.get(i).get("id"));
                txtSamItem.setLayoutParams(
                        new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 100, 1));
                // txtSamItem.setOnClickListener(featuredListener);
                txtSamItem.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        Intent i = new Intent(MainActivity.this, ApkInfo.class);
                        long id = Long.parseLong((String) arg0.getTag());
                        i.putExtra("_id", id);
                        i.putExtra("top", true);
                        i.putExtra("category", Category.TOPFEATURED.ordinal());
                        startActivity(i);
                    }
                });

                txtSamItem.measure(0, 0);

                if (i % 2 == 0) {
                    ll.addView(llAlso);

                    llAlso = new LinearLayout(MainActivity.this);
                    llAlso.setLayoutParams(
                            new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 100));
                    llAlso.setOrientation(LinearLayout.HORIZONTAL);
                    llAlso.addView(txtSamItem);
                } else {
                    llAlso.addView(txtSamItem);
                }
            }

            ll.addView(llAlso);
            SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(mContext);
            // System.out.println(sPref.getString("app_rating",
            // "All").equals(
            // "Mature"));
            ((ToggleButton) featuredView.findViewById(R.id.toggleButton1))
                    .setChecked(!sPref.getBoolean("matureChkBox", false));
            ((ToggleButton) featuredView.findViewById(R.id.toggleButton1))
                    .setOnCheckedChangeListener(adultCheckedListener);
        }
    });
}

From source file:cm.aptoide.pt.MainActivity.java

private void loadRecommended() {

    if (Login.isLoggedIn(mContext)) {
        ((TextView) featuredView.findViewById(R.id.recommended_text)).setVisibility(View.GONE);
    } else {// www  .j  a  v a  2 s . c o  m
        ((TextView) featuredView.findViewById(R.id.recommended_text)).setVisibility(View.VISIBLE);
    }

    new Thread(new Runnable() {

        private ArrayList<HashMap<String, String>> valuesRecommended;

        public void run() {
            loadUIRecommendedApps();
            File f = null;
            try {
                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp = spf.newSAXParser();
                NetworkUtils utils = new NetworkUtils();
                BufferedInputStream bis = new BufferedInputStream(
                        utils.getInputStream("http://webservices.aptoide.com/webservices/listUserBasedApks/"
                                + Login.getToken(mContext) + "/10/xml", null, null, mContext),
                        8 * 1024);
                f = File.createTempFile("abc", "abc");
                OutputStream out = new FileOutputStream(f);
                byte buf[] = new byte[1024];
                int len;
                while ((len = bis.read(buf)) > 0)
                    out.write(buf, 0, len);
                out.close();
                bis.close();
                String hash = Md5Handler.md5Calc(f);
                ViewApk parent_apk = new ViewApk();
                parent_apk.setApkid("recommended");
                if (!hash.equals(db.getItemBasedApksHash(parent_apk.getApkid()))) {
                    // Database.database.beginTransaction();
                    db.deleteItemBasedApks(parent_apk);
                    sp.parse(f, new HandlerItemBased(parent_apk));
                    db.insertItemBasedApkHash(hash, parent_apk.getApkid());
                    // Database.database.setTransactionSuccessful();
                    // Database.database.endTransaction();
                    loadUIRecommendedApps();
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

            if (f != null)
                f.delete();

        }

        private void loadUIRecommendedApps() {

            valuesRecommended = db.getItemBasedApksRecommended("recommended");

            runOnUiThread(new Runnable() {

                public void run() {

                    LinearLayout ll = (LinearLayout) featuredView.findViewById(R.id.recommended_container);
                    ll.removeAllViews();
                    LinearLayout llAlso = new LinearLayout(MainActivity.this);
                    llAlso.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                            LinearLayout.LayoutParams.WRAP_CONTENT));
                    llAlso.setOrientation(LinearLayout.HORIZONTAL);
                    if (valuesRecommended.isEmpty()) {
                        if (Login.isLoggedIn(mContext)) {
                            TextView tv = new TextView(mContext);
                            tv.setText(R.string.no_recommended_apps);
                            tv.setTextAppearance(mContext, android.R.attr.textAppearanceMedium);
                            tv.setPadding(10, 10, 10, 10);
                            ll.addView(tv);
                        }
                    } else {

                        for (int i = 0; i != valuesRecommended.size(); i++) {
                            LinearLayout txtSamItem = (LinearLayout) getLayoutInflater()
                                    .inflate(R.layout.row_grid_item, null);
                            ((TextView) txtSamItem.findViewById(R.id.name))
                                    .setText(valuesRecommended.get(i).get("name"));
                            ImageLoader.getInstance().displayImage(valuesRecommended.get(i).get("icon"),
                                    (ImageView) txtSamItem.findViewById(R.id.icon));
                            float stars = 0f;
                            try {
                                stars = Float.parseFloat(valuesRecommended.get(i).get("rating"));
                            } catch (Exception e) {
                                stars = 0f;
                            }
                            ((RatingBar) txtSamItem.findViewById(R.id.rating)).setIsIndicator(true);
                            ((RatingBar) txtSamItem.findViewById(R.id.rating)).setRating(stars);
                            txtSamItem.setPadding(10, 0, 0, 0);
                            // ((TextView)
                            // txtSamItem.findViewById(R.id.version))
                            // .setText(getString(R.string.version) +" "+
                            // valuesRecommended.get(i).get("vername"));
                            ((TextView) txtSamItem.findViewById(R.id.downloads))
                                    .setText("(" + valuesRecommended.get(i).get("downloads") + " "
                                            + getString(R.string.downloads) + ")");
                            txtSamItem.setTag(valuesRecommended.get(i).get("_id"));
                            txtSamItem.setLayoutParams(new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.MATCH_PARENT, 100, 1));
                            // txtSamItem.setOnClickListener(featuredListener);
                            txtSamItem.setOnClickListener(new OnClickListener() {

                                @Override
                                public void onClick(View arg0) {
                                    Intent i = new Intent(MainActivity.this, ApkInfo.class);
                                    long id = Long.parseLong((String) arg0.getTag());
                                    i.putExtra("_id", id);
                                    i.putExtra("top", true);
                                    i.putExtra("category", Category.ITEMBASED.ordinal());
                                    startActivity(i);
                                }
                            });

                            txtSamItem.measure(0, 0);

                            if (i % 2 == 0) {
                                ll.addView(llAlso);

                                llAlso = new LinearLayout(MainActivity.this);
                                llAlso.setLayoutParams(new LinearLayout.LayoutParams(
                                        LinearLayout.LayoutParams.MATCH_PARENT, 100));
                                llAlso.setOrientation(LinearLayout.HORIZONTAL);
                                llAlso.addView(txtSamItem);
                            } else {
                                llAlso.addView(txtSamItem);
                            }
                        }

                        ll.addView(llAlso);
                    }
                }
            });
        }
    }).start();

}