Android Open Source - palhike Welcome Activity






From Project

Back to project page palhike.

License

The source code is released under:

GNU General Public License

If you think the Android project palhike 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.palhike.android;
/*from www.  j a v  a2s.co  m*/
import java.util.Hashtable;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.SQLException;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;


public class WelcomeActivity extends Activity {
  LayoutInflater layoutInflater;
  RelativeLayout mapContainer;
  Cursor locations;
  int selectedLocation = 0;
  final int deviceWidth = 720;
  final int deviceHeight = 1280;
  
  public static final String strQrUrlNotRegistered = "-1";
  public Hashtable<String, String> urlMapper = new Hashtable<String, String>();
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (urlMapper.isEmpty()) {
      urlMapper.put("http://qr.w69b.com/g/pcwDVudoY", "1");
      urlMapper.put("http://qr.w69b.com/g/u6vvHAHEQ", "2");
      urlMapper.put("http://qr.w69b.com/g/s09qHfeeI", "3");
      urlMapper.put("http://qr.w69b.com/g/ovXIBfzEI", "4");
      urlMapper.put("http://qr.w69b.com/g/qY28fkKTC", "5");
      urlMapper.put("http://qr.w69b.com/g/o5Q4DZxZK", "6");
      urlMapper.put("http://qr.w69b.com/g/ucYFEsipG", "7");
      urlMapper.put("http://qr.w69b.com/g/tfyaNuekg", "8");
      urlMapper.put("http://qr.w69b.com/g/uS5x6dJ4Y", "9");
      urlMapper.put("http://qr.w69b.com/g/p5wDgJXVe", "10");
      urlMapper.put("http://qr.w69b.com/g/kWDEOfvcQ", "11");
      urlMapper.put("http://qr.w69b.com/g/q2tlqQXPq", "20");
      urlMapper.put("http://qr.w69b.com/g/nO0YFdgxq", "21");
      urlMapper.put("http://qr.w69b.com/g/pryh01Y9a", "22");
      urlMapper.put("http://qr.w69b.com/g/sXJ4OHWRW", "23");
      urlMapper.put("http://qr.w69b.com/g/n8LmI1SLe", "24");
      urlMapper.put("http://qr.w69b.com/g/mNUy6CnpC", "25");
      urlMapper.put("http://qr.w69b.com/g/kG9UMu5Yk", "26");
      urlMapper.put("http://qr.w69b.com/g/lPrL9wGCQ", "27");
      urlMapper.put("http://qr.w69b.com/g/ufeJqeEfK", "28");
      urlMapper.put("http://qr.w69b.com/g/q6lKXKbxm", "29");
      urlMapper.put("http://qr.w69b.com/g/nsCim6CFa", "30");
      urlMapper.put("http://qr.w69b.com/g/mw5s7Q5Xi", "31");
      urlMapper.put("http://qr.w69b.com/g/sitsRwz5K", "32");
      urlMapper.put("http://qr.w69b.com/g/qZ9Rj1mXm", "33");
      urlMapper.put("http://qr.w69b.com/g/lRHOVj2sU", "34");
      urlMapper.put("http://qr.w69b.com/g/nwuHSZQn6", "35");
      urlMapper.put("http://qr.w69b.com/g/rpNEjlcY0", "36");
      urlMapper.put("http://qr.w69b.com/g/rrMq6Hf20", "37");
      urlMapper.put("http://qr.w69b.com/g/t3VO7sSWc", "38");
      
      
      urlMapper.put("http://qr.w69b.com/g/mHYJkXx96", "100");
      urlMapper.put("http://qr.w69b.com/g/t89xpMTcc", "101");
      urlMapper.put("http://qr.w69b.com/g/okAC36KBi", "102");
      urlMapper.put("http://qr.w69b.com/g/tqd0Snyr6", "103");
      urlMapper.put("http://qr.w69b.com/g/qMotIV52o", "104");
      urlMapper.put("http://qr.w69b.com/g/prSikJLzO", "105");
      urlMapper.put("http://qr.w69b.com/g/o1z8POrMk", "106");
      urlMapper.put("http://qr.w69b.com/g/o3ZDItMDm", "107");
      urlMapper.put("http://qr.w69b.com/g/sbX9bnZsI", "108");
      urlMapper.put("http://qr.w69b.com/g/pIw6UyUPm", "109");
      urlMapper.put("http://qr.w69b.com/g/mQXL1IRzy", "110");
      urlMapper.put("http://qr.w69b.com/g/tuUAnyyLS", "111");
      urlMapper.put("http://qr.w69b.com/g/mGvUIV2hy", "112");
      urlMapper.put("http://qr.w69b.com/g/rMIN8V61i", "113");
      urlMapper.put("http://qr.w69b.com/g/s0FRbdxU4", "114");
      urlMapper.put("http://qr.w69b.com/g/s0ShNjHLq", "115");
      urlMapper.put("http://qr.w69b.com/g/tdHJRYsXS", "116");
      urlMapper.put("http://qr.w69b.com/g/pKuQdva8g", "117");
      urlMapper.put("http://qr.w69b.com/g/pC666DEis", "118");
      urlMapper.put("http://qr.w69b.com/g/tuiIcBqVO", "119");
      urlMapper.put("http://qr.w69b.com/g/s1ERlp0DC", "120");
      urlMapper.put("http://qr.w69b.com/g/mYzobvHws", "121");
      urlMapper.put("http://qr.w69b.com/g/ooZb4jh96", "122");
      urlMapper.put("http://qr.w69b.com/g/o4btZVieI", "123");
      urlMapper.put("http://qr.w69b.com/g/qGPMNppvi", "124");
      urlMapper.put("http://qr.w69b.com/g/s8hul0nQY", "125");
      urlMapper.put("http://qr.w69b.com/g/ocxqEaJS8", "126");
      urlMapper.put("http://qr.w69b.com/g/qY5g4wBEY", "127");
      urlMapper.put("http://qr.w69b.com/g/o6YJIF4l2", "128");
      urlMapper.put("http://qr.w69b.com/g/n3gXGGHRe", "129");
      urlMapper.put("http://qr.w69b.com/g/t0WYXRrTW", "130");
      urlMapper.put("http://qr.w69b.com/g/pcRK4aKR2", "131");
      urlMapper.put("http://qr.w69b.com/g/prNOgEFtm", "132");
      urlMapper.put("http://qr.w69b.com/g/mM47b6C3e", "133");
    }
    setContentView(R.layout.activity_welcome);
    layoutInflater = LayoutInflater.from(this);
    
    mapContainer = (RelativeLayout) findViewById(R.id.mapContainer);
    TestAdapter adapter = new TestAdapter(getBaseContext());
    try {
      adapter = adapter.createDatabase();
    } catch (Exception e) {
      
    }
    adapter.close();
    adapter = adapter.open();
    locations = adapter.getLocations();
    locations.moveToPosition(-1);
    while (locations.moveToNext()) {
      String coordinates = locations.getString(locations.getColumnIndex("coordinates"));
      String[] coordArray = coordinates.split(",");
      double XCoordRatio = Double.parseDouble(coordArray[0]);
      double YCoordRatio = Double.parseDouble(coordArray[1]);
      XCoordRatio = XCoordRatio*deviceWidth;
      YCoordRatio=YCoordRatio*deviceHeight;
      int XCoord = (int) Math.round(XCoordRatio)- (int) Math.round(0.02*XCoordRatio);
      int YCoord = (int) Math.round(YCoordRatio) - (int) Math.round(0.13*YCoordRatio);
     ImageView image = (ImageView) layoutInflater.inflate(R.layout.location_image, null );
     int id = locations.getInt(locations.getColumnIndex("_id"));
     image.setTag(String.valueOf(id));
     RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(50,50); // The desired size of the child
     params.setMargins(XCoord,YCoord, 0, 0);
     mapContainer.addView(image,params);
     
    Button scanBtn = (Button) findViewById(R.id.scanButton);
    scanBtn.setOnClickListener(new OnClickListener(){
      @Override
      public void onClick(View v) {
        IntentIntegrator integrator = new IntentIntegrator(
            WelcomeActivity.this);
        integrator.initiateScan();  
      }
      
    });
     
    }
        
     
  }
  
  @Override
  public void onBackPressed(){
    Intent goToSettings = new Intent(this,Login.class);
    startActivity(goToSettings);
    
  }
  
  public void markLocation(String tagId){
    if(selectedLocation!=0){
      ImageView removedImage = (ImageView) mapContainer.findViewWithTag(String.valueOf(selectedLocation));
      //removedImage.setImageDrawable(getResources().getDrawable(R.drawable.location_image_off));
      removedImage.setImageResource(android.R.color.transparent);
    }
    ImageView selectedImage = (ImageView) mapContainer.findViewWithTag(tagId);
    selectedImage.setImageDrawable(getResources().getDrawable(R.drawable.location_image_on));
    
     selectedLocation= Integer.valueOf(tagId);
  }
  
  public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    if ( intent==null)
    {
      finish();
      startActivity(getIntent());
      return;
    }
    IntentResult scanResult = IntentIntegrator.parseActivityResult(
        requestCode, resultCode, intent);
    if (scanResult == null) {
      Toast.makeText(getBaseContext(), "Wrong QR Code ",
          Toast.LENGTH_LONG).show();
    }
    String url = scanResult.getContents();
    if (url == null) {
      // cancled scanning
      finish();
      startActivity(getIntent());
      return;
    }
    
    SharedPreferences shared = getSharedPreferences("com.example.hike",
        MODE_PRIVATE);
    String language = (shared.getString("language", ""));
    
    
    String resultIdString = urlMapper.containsKey(url) ? urlMapper.get(url) : strQrUrlNotRegistered;
      if (resultIdString.equals(strQrUrlNotRegistered)) {
        Toast.makeText(getBaseContext(), "Could not find tree...: " + resultIdString,
            Toast.LENGTH_LONG).show();
        finish();
        startActivity(getIntent());
        return;
      }
    int resultId = Integer.valueOf(resultIdString);
    if(resultId>=100){
      try {
        
        markLocation(String.valueOf(resultId));
      } catch (SQLException e) {
        return;
      } catch (Exception ex) {
        return;
      }  
    }
    else{
      
      Intent goToPage = new Intent(this, TreeTabs.class);
      goToPage.putExtra("resultIdString", resultIdString);
      goToPage.putExtra("language", language);
      startActivity(goToPage);
      
//      // handle tree qr
//      try {
//        TestAdapter database = new TestAdapter(getBaseContext());
//        database = database.open();
//
//        ObjectModel data = database.getObject(resultIdString, "minor", language);
//        if (data == null) {
//          finish();
//          startActivity(getIntent());
//          return;
//        }
//
//        Intent goToPage = new Intent(this, TreeTabs.class);
//        goToPage.putExtra("title", data._title);
//        goToPage.putExtra("description", data._description);
//        goToPage.putExtra("image1", data._image1);
//        goToPage.putExtra("image2", data._image2);
//        goToPage.putExtra("image3", data._image3);
//        goToPage.putExtra("image4", data._image4);
//        goToPage.putExtra("image5", data._image5);
//        goToPage.putExtra("num_images", data._num_images);
//
//        startActivity(goToPage);
//      } catch (SQLException e) {
//
//        Toast.makeText(getBaseContext(), "SQLException: " + e.getMessage(),
//            Toast.LENGTH_LONG).show();
//        finish();
//        startActivity(getIntent());
//        return;
//      } catch (Exception ex) {
//        Toast.makeText(getBaseContext(), ex.getMessage(), Toast.LENGTH_LONG)
//            .show();
//        finish();
//        startActivity(getIntent());
//        return;
//      }  
    }
        
  }
  
}




Java Source Code List

com.palhike.android.DataBaseHelper.java
com.palhike.android.Details.java
com.palhike.android.FragmentInfo.java
com.palhike.android.Home.java
com.palhike.android.IntentIntegrator.java
com.palhike.android.IntentResult.java
com.palhike.android.Login.java
com.palhike.android.ObjectModel.java
com.palhike.android.Page.java
com.palhike.android.SettingsActivity.java
com.palhike.android.TestAdapter.java
com.palhike.android.TreeTabs.java
com.palhike.android.TreeViewData.java
com.palhike.android.WelcomeActivity.java