Android Open Source - AerisAndroidLibrary My Locs Activity






From Project

Back to project page AerisAndroidLibrary.

License

The source code is released under:

Apache License

If you think the Android project AerisAndroidLibrary listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.demoaerisproject;
/*from   w ww  .ja  va2 s  . c  om*/
import java.util.List;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.Window;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.LayoutParams;
import android.widget.RadioGroup.OnCheckedChangeListener;

import com.example.db.MyPlace;
import com.example.db.MyPlacesDb;
import com.example.demoaerisproject.AerisDialog.AerisDialogOKListener;

public class MyLocsActivity extends Activity implements OnLongClickListener,
    OnCheckedChangeListener, AerisDialogOKListener {

  private RadioGroup locationGroup;
  private List<MyPlace> places;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    this.setContentView(R.layout.activity_my_location);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    locationGroup = (RadioGroup) this.findViewById(R.id.rgLocations);
    locationGroup.setOnCheckedChangeListener(this);
    addRadioButtons();
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    // Respond to the action bar's Up/Home button
    case android.R.id.home:
      super.onBackPressed();
      return true;
    }
    return super.onOptionsItemSelected(item);
  }

  private void addRadioButtons() {
    locationGroup.removeAllViews();
    MyPlacesDb db = new MyPlacesDb(this);
    places = db.getPlaces();
    for (int i = 0; i < places.size(); i++) {
      MyPlace place = places.get(i);
      RadioButton button = (RadioButton) getLayoutInflater().inflate(
          R.layout.aeris_radio_button, null);
      final float scale = getResources().getDisplayMetrics().density;
      int pixels = (int) (getResources().getInteger(
          R.integer.min_click_height)
          * scale + 0.5f);
      button.setText(place.getTextDisplay("Null"));
      button.setTag(i);
      locationGroup.addView(button, LayoutParams.MATCH_PARENT, pixels);
      button.setOnLongClickListener(this);
    }

    for (int i = 0; i < places.size(); i++) {
      if (places.get(i).myLoc) {
        setCheckedAtIndex(i, locationGroup);
        break;
      }
    }

  }

  private void setCheckedAtIndex(int index, RadioGroup group) {
    RadioButton radioButton = (RadioButton) group.getChildAt(index);
    radioButton.setChecked(true);
  }

  @Override
  public void onCheckedChanged(RadioGroup group, int checkedId) {
    int radioButtonID = group.getCheckedRadioButtonId();
    RadioButton radioButton = (RadioButton) group
        .findViewById(radioButtonID);
    int index = group.indexOfChild(radioButton);
    MyPlacesDb db = new MyPlacesDb(this);
    MyPlace place = places.get(index);
    db.insertPlaces(place.name, place.state, place.country, place.latitude,
        place.longitude, true);
    db.close();
  }

  @Override
  public boolean onLongClick(View v) {
    MyPlace place = places.get((Integer) v.getTag());
    AerisDialog dialog = new AerisDialog()
        .withMessage("Delete this location?").withListener(this)
        .withType(1).withObject(place);
    dialog.show(getFragmentManager(), "delete_location");
    return false;
  }

  @Override
  public void onOKPressed(int type, Object object) {
    if (type == 1) {
      MyPlace place = (MyPlace) object;
      MyPlacesDb db = new MyPlacesDb(this);
      db.deletePlace(place);
      db.close();
      addRadioButtons();
    }
  }
}




Java Source Code List

aeris.AerisUnusedStub.java
com.example.customendpoint.CustomEndpointAdapter.java
com.example.customendpoint.CustomMoonModel.java
com.example.customendpoint.CustomSunModel.java
com.example.customendpoint.CustomSunmoonFragment.java
com.example.customendpoint.CustomSunmoonHolder.java
com.example.customendpoint.CustomSunmoonModel.java
com.example.customendpoint.CustomSunmoonResponse.java
com.example.db.MyLocLoader.java
com.example.db.MyPlace.java
com.example.db.MyPlacesDb.java
com.example.db.MyPlacesSubject.java
com.example.db.SimpleCursorLoader.java
com.example.demoaerisproject.AerisDialog.java
com.example.demoaerisproject.AerisNotification.java
com.example.demoaerisproject.BaseApplication.java
com.example.demoaerisproject.DrawerActivity.java
com.example.demoaerisproject.LocationSearchActivity.java
com.example.demoaerisproject.MyLocsActivity.java
com.example.demoaerisproject.SettingsActivity.java
com.example.edithelp.EditTextEnterListener.java
com.example.edithelp.EnterPressedDelegate.java
com.example.fragment.AerisFragment.java
com.example.fragment.AerisPrefFragment.java
com.example.fragment.ExtForecastFragment.java
com.example.fragment.HeadlessFragment.java
com.example.fragment.MapFragment.java
com.example.fragment.NearbyObsFragment.java
com.example.fragment.ObservationFragment.java
com.example.fragment.OverviewFragment.java
com.example.fragment.RecentObsFragment.java
com.example.fragment.RefreshInterface.java
com.example.fragment.SplashFragment.java
com.example.fragment.WeekendFragment.java
com.example.listview.AdapterHolder.java
com.example.listview.DayNightPeriod.java
com.example.listview.ForecastAdapter.java
com.example.listview.ForecastItemHolder.java
com.example.listview.IndexMonitorAdapter.java
com.example.listview.ListAdapter.java
com.example.listview.ObservationAdapter.java
com.example.listview.ObservationItemHolder.java
com.example.listview.ObservationPeriodAdapter.java
com.example.listview.PlacesAdapter.java
com.example.listview.PlacesItemHolder.java
com.example.listview.RecentObsHolder.java
com.example.listview.WeekendAdapter.java
com.example.listview.WeekendItemHolder.java
com.example.menudrawer.HomeFragment.java
com.example.menudrawer.NavDrawerItem.java
com.example.menudrawer.NavDrawerListAdapter.java
com.example.preference.PrefManager.java
com.example.service.NotificationService.java
com.example.service.ScreenOnReceiver.java
com.example.service.ScreenOnService.java
com.example.util.FormatUtil.java
com.example.view.DayNightView.java
com.example.view.SmallForecastView.java
com.example.view.TemperatureInfoData.java
com.example.view.TemperatureWindowAdapter.java
com.example.view.TwoPartView.java