Android Open Source - videoMerge Upload Info Fragment






From Project

Back to project page videoMerge.

License

The source code is released under:

Apache License

If you think the Android project videoMerge 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.dragonplayer.merge.fragment;
//from  ww w.  jav  a2  s .c o m
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.*;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.*;
import android.widget.TextView.OnEditorActionListener;

import com.dragonplayer.merge.LoadingDialog;
import com.dragonplayer.merge.MainActivity;
import com.dragonplayer.merge.R;
import com.dragonplayer.merge.adapter.ProjectListAdapter;
import com.dragonplayer.merge.frames.Frames;
import com.dragonplayer.merge.frames.ProjectFiles;
import com.dragonplayer.merge.utils.AppConnectivity;
import com.dragonplayer.merge.utils.BannerData;
import com.dragonplayer.merge.utils.BitmapUtil;
import com.dragonplayer.merge.utils.DlgWindow1;
import com.dragonplayer.merge.utils.DlgWindow4;
import com.dragonplayer.merge.utils.MLog;
import com.dragonplayer.merge.utils.Utils;
import com.dragonplayer.merge.utils.WeTouch_network_interface;
import com.dragonplayer.merge.utils.WeTouch_uploadImage;
import com.dragonplayer.merge.utils.WebService;

import java.io.File;
import java.lang.reflect.Field;
import java.util.Calendar;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
 * 
 * @author ??????
 *
 */
public class UploadInfoFragment extends Fragment {

  EditText editUserName;
  EditText editEMail;
  EditText editTel;
  ImageView imgMedia;

  String filePath;
  Button btnRegister;
  LoadingDialog mLoadingProgress;

  String strUserName = "";
  String strEMail = "";
  String strTel = "";
  Dialog mDialog;
  
    public void onActivityCreated(Bundle bundle) {
        super.onActivityCreated(bundle);
        MLog.e(this,"onActivityCreated");
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setRetainInstance(true);
        
        filePath = getArguments().getString("filepath");

        if (bundle != null) {
          if (bundle.containsKey("editusername"))
            strUserName = bundle.getString("editusername");
          if (bundle.containsKey("editemail"))
            strEMail = bundle.getString("editemail");
          if (bundle.containsKey("edittel"))
            strTel = bundle.getString("edittel");
        }
    }

    public void onSaveInstanceState(Bundle bundle) {
      
      bundle.putString("editusername", editUserName.getText().toString());
      bundle.putString("editemail", editEMail.getText().toString());
      bundle.putString("edittel", editTel.getText().toString());
        
        super.onSaveInstanceState(bundle);
    }

    public View onCreateView(LayoutInflater layoutinflater, ViewGroup viewgroup, Bundle bundle) {
        View view = layoutinflater.inflate(R.layout.upload_info_fragment, viewgroup, false);
        
      editUserName = (EditText) view.findViewById(R.id.username);
      editEMail = (EditText) view.findViewById(R.id.email);
      editTel = (EditText) view.findViewById(R.id.tel);

      editUserName.setText(strUserName);
      editEMail.setText(strEMail);
      editTel.setText(strTel);
      
      imgMedia = (ImageView) view.findViewById(R.id.imgmedia);
      LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) imgMedia.getLayoutParams();
      DisplayMetrics displaymetrics = getActivity().getResources().getDisplayMetrics();
      params.height = displaymetrics.widthPixels * 120 / 721;
      imgMedia.setLayoutParams(params);
      imgMedia.getViewTreeObserver().addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() {

            public void onGlobalLayout() {
              imgMedia.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        
              if (filePath == null || filePath.isEmpty())
                return;
              
                int screenWidth = getActivity().getResources().getDisplayMetrics().widthPixels;
                int screenHeight = getActivity().getResources().getDisplayMetrics().heightPixels;
                int itemHeight = imgMedia.getHeight(); 
                int itemWidth = itemHeight * screenWidth / screenHeight;
                
                if (filePath.contains("mp4")) {
                  File file = Utils.writeToFile(BitmapUtil.videoFrame(filePath, 0L));
                  ((MainActivity)getActivity()).getManager().displayThumbImage(file.getAbsolutePath(), imgMedia, itemWidth, itemHeight);
                  file.delete();
                }
                else {
                    ((MainActivity)getActivity()).getManager().displayThumbImage(filePath, imgMedia, itemWidth, itemHeight);
                }
            }
        });
        
      imgMedia.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        ((MainActivity)getActivity()).onClickUploadMedia();
      }
        
      });
      
      btnRegister = (Button) view.findViewById(R.id.btnregister);
      btnRegister.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub

        String username = editUserName.getText().toString();
        String tel = editTel.getText().toString();
        String email = editEMail.getText().toString();

        if (username.isEmpty() || tel.isEmpty() || email.isEmpty()) {
          
          mDialog = new DlgWindow4(getActivity(), R.style.CustomDialog, "????????", "??", new OnClickListener() {

            @Override
            public void onClick(View v) {
              // TODO Auto-generated method stub
              mDialog.dismiss();
            }
                });
          mDialog.show();
                return;
        }
        if (tel.length()<7) {
          mDialog = new DlgWindow4(getActivity(), R.style.CustomDialog, "??????", "??", new OnClickListener() {

            @Override
            public void onClick(View v) {
              // TODO Auto-generated method stub
              mDialog.dismiss();
            }
                });
          mDialog.show();
                return;
        }
        if (!isValidVerification(email)) {
          mDialog = new DlgWindow4(getActivity(), R.style.CustomDialog, "???????", "??", new OnClickListener() {

            @Override
            public void onClick(View v) {
              // TODO Auto-generated method stub
              mDialog.dismiss();
            }
                });
          mDialog.show();
                return;
        }
        
        mDialog = new DlgWindow4(getActivity(), R.style.CustomDialog, "????????????", "??", new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            mDialog.dismiss();

                      AppConnectivity connection = new AppConnectivity(getActivity().getApplicationContext());
                  boolean isInternet = connection.isConnectingToInternet();
                  
                  if (!isInternet) {
                mDialog = new DlgWindow4(getActivity(), R.style.CustomDialog, "?????????", "??", new OnClickListener() {

                  @Override
                  public void onClick(View v) {
                    // TODO Auto-generated method stub
                    mDialog.dismiss();
                  }
                      });
                mDialog.show();
                      return;
                  }

                  String actId = String.valueOf(Calendar.getInstance().getTimeInMillis());
              String username = editUserName.getText().toString();
              String tel = editTel.getText().toString();
              String email = editEMail.getText().toString();
                  String facebook = "";
                     
              mLoadingProgress = new LoadingDialog(getActivity());
              mLoadingProgress.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
              mLoadingProgress.show();
              
                  AsyncCallWS task = new AsyncCallWS();
              task.execute(actId, username, tel, email, facebook);
          }
              });
        mDialog.show();
      }
        
      });
        
        return view;
    }

    private boolean isValidVerification(String id) {
      int cityCode[] = {10, 11, 12, 13, 14, 15, 16, 17, 34, 18, 19, 20, 21, 22, 35, 23, 24, 25, 26, 27, 
              28, 29, 32, 30, 31, 33};
      int mulCode[] = {1, 9, 8, 7, 6, 5, 4, 3, 2, 1};
      int idCode[] = new int[10];
      int verificationCode = 0;
      int i;
      
      if (id.length() != 10)
        return false;
      
      if (id.charAt(0) < 'A' || id.charAt(0) > 'Z')
        return false;

      idCode[0] = cityCode[id.charAt(0) - 'A'] / 10;
      idCode[1] = cityCode[id.charAt(0) - 'A'] % 10;
      
      for (i = 1; i < 10; i++) {
          if (id.charAt(i) < '0' || id.charAt(i) > '9')
            return false;
          
          if (i < 9) {
            idCode[i+1] = id.charAt(i) - '0';
          }
          else {
            verificationCode = id.charAt(i) - '0';
          }
      }
      
      int sum = 0;
      for (i = 0; i < 10; i++) {
        sum = sum + mulCode[i] * idCode[i]; 
      }
      
      if ((10 - (sum % 10)) == verificationCode)
        return true;
      
      return false;
    }
    
    public void onDetach() {
      
        try {
            Field field = Fragment.class.getDeclaredField("mChildFragmentManager");
            field.setAccessible(true);
            field.set(this, null);
        }
        catch(NoSuchFieldException nosuchfieldexception) {
            throw new RuntimeException(nosuchfieldexception);
        }
        catch(IllegalAccessException illegalaccessexception) {
            throw new RuntimeException(illegalaccessexception);
        }
        
        super.onDetach();
    }

  private class AsyncCallWS extends AsyncTask<String, Void, Void> {
    
    private String mResult = "";
    String actId;
    String username;
    String tel;
    String email;
    String facebook;
    
    @Override
    protected Void doInBackground(String... params) {
      actId = params[0];
      username = params[1];
      tel = params[2];
      email = params[3];
      facebook = params[4];
      
      mResult = WebService.JAct(actId, username, tel, email, facebook, "JAct");
          
      WeTouch_uploadImage task = new WeTouch_uploadImage(getActivity(), new WeTouch_network_interface() {

        @Override
        public void onImageUploadComplete(String result) {
          // TODO Auto-generated method stub
          Log.e("upload result", result);
        }
        
      });
      
      task.execute("http://211.78.89.41:81/pp/upload_test/upload_test.php", filePath);
       
      return null;
    }

    @Override
    protected void onPostExecute(Void result) {
      if (mLoadingProgress != null) {
        mLoadingProgress.dismiss();
        mLoadingProgress = null;
      }
      
      if (mResult.toUpperCase().equals("YES")) {
        SharedPreferences sp = getActivity().getSharedPreferences("iDragon", Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putString("actId", actId);
        editor.putString("tel", tel);
        editor.putString("username", username);
        editor.putString("email", email);
        editor.putString("filepath", filePath);
        editor.commit();
        
        mDialog = new DlgWindow4(getActivity(), R.style.CustomDialog, "?????", "??", new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            //((MainActivity)getActivity()).onClickUploadConfirm(actId, username, email, tel, filePath);
            //???????.?????????????
            ((MainActivity)getActivity()).onClickLockConfirm(actId, username, email, tel, filePath);
            mDialog.dismiss();
          }
              });
        mDialog.show();
      }
      else {
      }
    }

    @Override
    protected void onPreExecute() {
    }

    @Override
    protected void onProgressUpdate(Void... values) {
    }
  }
}




Java Source Code List

com.dragonplayer.merge.FBLikeActivity.java
com.dragonplayer.merge.FacebookActivity.java
com.dragonplayer.merge.FacebookEventObserver.java
com.dragonplayer.merge.LoadingDialog.java
com.dragonplayer.merge.MainActivity.java
com.dragonplayer.merge.SplashActivity.java
com.dragonplayer.merge.TextInputActivity.java
com.dragonplayer.merge.adapter.FrameListAdapter.java
com.dragonplayer.merge.adapter.FrameSubListAdapter.java
com.dragonplayer.merge.adapter.MediaListAdapter.java
com.dragonplayer.merge.adapter.ProjectListAdapter.java
com.dragonplayer.merge.adapter.ProjectSubListAdapter.java
com.dragonplayer.merge.fragment.AboutFragment.java
com.dragonplayer.merge.fragment.AddAudioFragment.java
com.dragonplayer.merge.fragment.BaseFragment.java
com.dragonplayer.merge.fragment.FinishFragment.java
com.dragonplayer.merge.fragment.FrameFragment.java
com.dragonplayer.merge.fragment.FrameListFragment.java
com.dragonplayer.merge.fragment.GiftFragment.java
com.dragonplayer.merge.fragment.GridFragment.java
com.dragonplayer.merge.fragment.HomeFragment.java
com.dragonplayer.merge.fragment.LockConfirmFragment.java
com.dragonplayer.merge.fragment.LockFragment.java
com.dragonplayer.merge.fragment.UploadConfirmFragment.java
com.dragonplayer.merge.fragment.UploadFragment.java
com.dragonplayer.merge.fragment.UploadInfoFragment.java
com.dragonplayer.merge.fragment.UploadSelectMediaFragment.java
com.dragonplayer.merge.fragment.WorkFragment.java
com.dragonplayer.merge.frames.FrameInfo.java
com.dragonplayer.merge.frames.FramePart.java
com.dragonplayer.merge.frames.FrameView.java
com.dragonplayer.merge.frames.Frame.java
com.dragonplayer.merge.frames.FramesLayout.java
com.dragonplayer.merge.frames.Frames.java
com.dragonplayer.merge.frames.HorizontalListView.java
com.dragonplayer.merge.frames.ProjectFiles.java
com.dragonplayer.merge.frames.timeout.java
com.dragonplayer.merge.utils.AppConnectivity.java
com.dragonplayer.merge.utils.BannerData.java
com.dragonplayer.merge.utils.BitmapManager.java
com.dragonplayer.merge.utils.BitmapUtil.java
com.dragonplayer.merge.utils.Constants.java
com.dragonplayer.merge.utils.DlgWindow1.java
com.dragonplayer.merge.utils.DlgWindow2.java
com.dragonplayer.merge.utils.DlgWindow4.java
com.dragonplayer.merge.utils.DlgWindow5.java
com.dragonplayer.merge.utils.DlgWindow6.java
com.dragonplayer.merge.utils.DlgWindow7.java
com.dragonplayer.merge.utils.DlgWindow8.java
com.dragonplayer.merge.utils.FileMover.java
com.dragonplayer.merge.utils.Flag.java
com.dragonplayer.merge.utils.MLog.java
com.dragonplayer.merge.utils.SingleMediaScanner.java
com.dragonplayer.merge.utils.Utils.java
com.dragonplayer.merge.utils.WeTouch_network_interface.java
com.dragonplayer.merge.utils.WeTouch_uploadImage.java
com.dragonplayer.merge.utils.WebService.java