2013-10-30 20 views
1
 public class MovieDescription extends Activity { 

Vibrator vibrator; 
TextView tv_title,tv_year,tv_banner,tv_desc; 
RatingBar ratingBar; 
ImageView iv_watch,iv_poster; 
private static final String TAG_CONTACTS = "Demo"; 
private static final String TAG_ID = "id"; 
private static final String TAG_TITLE = "title"; 
private static final String TAG_YEAR = "year"; 
private static final String TAG_RATING = "rating"; 
private static final String TAG_BANNER= "category"; 
private static final String TAG_DESC = "description"; 
private static final String TAG_URL = "url"; 
private static final String TAG_POSTER = "poster"; 
    String id,title,year,rating,banner,description,poster, movieUrl; 
static JSONArray contacts = null; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.movie_description); 
    initialize(); 



    String movieDescUrl = "http://vaibhavtech.com/work/android/movie_description.php?id="+MainActivity.movie_Id; 

    MovieDescriptionParser jParser = new MovieDescriptionParser(); 
    JSONObject json = jParser.getJSONFromUrl(movieDescUrl); 

    try { 
contacts = json.getJSONArray(TAG_CONTACTS); 
     for (int i = 0; i < contacts.length(); i++) 
     { 
      /**********************************Value Parse FromUrl**********************************/ 
      JSONObject c = contacts.getJSONObject(i); 
      id = c.getString(TAG_ID); 
      title = c.getString(TAG_TITLE); 
      year = c.getString(TAG_YEAR); 
      rating = c.getString(TAG_RATING); 
      banner=c.getString(TAG_BANNER); 
      description = c.getString(TAG_DESC); 
      movieUrl = c.getString(TAG_URL); 
      poster = c.getString(TAG_POSTER); 
      /**********************************Valeu Assing to UI Component**********************************/ 

      Log.i(id, title); 
     } 
    } catch (JSONException e) { 
     e.printStackTrace(); 
    } 

    tv_title.setText(title); 
    tv_year.setText(year); 
    tv_banner.setText(banner); 
    tv_desc.setText(description); 
    Float rat=Float.parseFloat(rating); 
    ratingBar.setRating(rat); 

    Bitmap bimage= getBitmapFromURL("http://vaibhavtech.com/work/android/admin/upload/"+poster); 
    iv_poster.setImageBitmap(bimage); 

    iv_watch.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      vibrator.vibrate(40); 
      LayoutInflater inflater=getLayoutInflater(); 
      View view=inflater.inflate(R.layout.customtoast,(ViewGroup)findViewById(R.id.custom_toast_layout)); 
      Toast toast=new Toast(getApplicationContext()); 
      toast.setDuration(Toast.LENGTH_LONG); 
      toast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0); 
      toast.setView(view); 
      toast.show(); 
      Intent intent=new Intent(Intent.ACTION_VIEW); 
      intent.setData(Uri.parse(movieUrl)); 
      startActivity(intent); 
     } 
    }); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // TODO Auto-generated method stub 
    int currentapiVersion = android.os.Build.VERSION.SDK_INT; 
    Log.i("Device Versoin is", ""+currentapiVersion); 
    if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN){ 
     ActionBar actionBar = getActionBar(); 
     actionBar.setHomeButtonEnabled(true); 
     actionBar.setDisplayHomeAsUpEnabled(true); 
     getMenuInflater().inflate(R.menu.main, menu); 
} 

    return super.onCreateOptionsMenu(menu); 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // TODO Auto-generated method stub 

    switch (item.getItemId()) { 
    case android.R.id.home: 
     onBackPressed(); 
     return true; 
    case R.id.home: 
     Intent intent = new Intent(this, MainActivity.class); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     startActivity(intent); 
     Log.i("Home", "Press"); 
     return true; 

    } 
    return super.onOptionsItemSelected(item); 
} 

public void initialize() 
{ 
    tv_banner=(TextView) findViewById(R.id.tv_movie_description_banner); 
    tv_desc=(TextView) findViewById(R.id.tv_movie_description_decription); 
    tv_title=(TextView) findViewById(R.id.tv_movie_description_name); 
    tv_year=(TextView) findViewById(R.id.tv_movie_description_year); 
    ratingBar=(RatingBar) findViewById(R.id.ratingBar1); 
    iv_watch=(ImageView) findViewById(R.id.iv_movie_description_watch); 
    iv_poster=(ImageView) findViewById(R.id.iv_movie_description_poster); 
    vibrator=(Vibrator)getSystemService(Context.VIBRATOR_SERVICE);; 
} 
public static Bitmap getBitmapFromURL(String src) { 
    try { 
     Log.i("src",src); 
     URL url = new URL(src); 
     HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
     connection.setDoInput(true); 
     connection.connect(); 
     InputStream input = connection.getInputStream(); 
     Bitmap myBitmap = BitmapFactory.decodeStream(input); 
     Log.i("Bitmap","returned"); 
     return myBitmap; 
    } catch (IOException e) { 
     e.printStackTrace(); 
     Log.e("Exception",e.getMessage()); 
     return null; 
     } 
    } 
} 

當我clciking上現在表扣其給我4個選項-by mozilz,通過鍍鉻,由YouTube, 我想,當我在觀看點擊按鈕,現在它得到重定向YouTube上的網址鏈接,我..怎麼能做到這一點,請給我任何suggetion :(如何在YouTube上重定向的Android

回答

1

試試這個:

Intent i = app.getPackageManager().getLaunchIntentForPackage("com.google.android.youtube"); 
if (i != null) 
app.startActivity(i); 

檢查這個環節也:Redirect YouTube in Android

希望這有助於。

+0

嗨androiduser,謝謝你的這個鏈接。 – AntonSack