Android Open Source - AndroidFileBroadcast Screen1






From Project

Back to project page AndroidFileBroadcast.

License

The source code is released under:

Apache License

If you think the Android project AndroidFileBroadcast 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.bucketdevelopers.uft;
//from   w  ww. j av a 2  s.c  om
import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.bucketdevelopers.uft.ServerService;
import com.common.methods.AvailableSpaceHandler;
import com.common.methods.IpAddress;
import com.common.methods.qrcodelibrary.Contents;
import com.common.methods.qrcodelibrary.QRCodeEncoder;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class Screen1 extends Fragment {

  private Intent uploaddownloadservice;
  public static int PORT = 8080;
  private String qrData;
  private ImageView qrimagesmall;
  private TextView sdspaceavail;

  public static final Screen1 newInstance(String message)

  {

    Screen1 f = new Screen1();
    Bundle bdl = new Bundle(1);

    f.setArguments(bdl);
    return f;

  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,

  Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.screen1, container, false);
    sdspaceavail = (TextView) v.findViewById(R.id.sdspace);
    uploaddownloadservice = new Intent(getActivity(), ServerService.class);

    // Setting the SD Card Space
    updateSDSpace();

    // Start\Stop the Server
    final TextView transfer_text = (TextView) v.findViewById(R.id.transfer_text);
    final ImageButton serverToggle = (ImageButton) v
        .findViewById(R.id.ServerEnable);

    if(ServerService.serverenabled==true)
    {
      transfer_text.setText("1.Disable transfer");
      
    }
    else
    {
      transfer_text.setText("1.Enable transfer");
      
    }
    serverToggle.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {

        // Start The service
        if (ServerService.serverenabled != true) {

          // Bug Fix:
          // Just So that App doesnt FORCE CLOSE even for some
          // reason the UI is ******
          getActivity().stopService(uploaddownloadservice);

          // Now the Real Deal
          Log.d("tag", "Starting");
          uploaddownloadservice.putExtra("Port", PORT);
          getActivity().startService(uploaddownloadservice);
          transfer_text.setText("1.Disable transfer");
          updateIP(true);

        } else {
          getActivity().stopService(uploaddownloadservice);
          transfer_text.setText("1.Enable transfer");
          ServerService.serverenabled = false;
          updateIP(false);
        }
        
        updateSDSpace();
      }
    });

    // Switch to next Fragment (File Selection)
    ImageButton fileselect = (ImageButton) v
        .findViewById(R.id.fileSelector);
    fileselect.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View vw) {
        ViewPager pager = (ViewPager) getActivity().findViewById(
            R.id.viewpager);
        pager.setCurrentItem(1, true);

      }
    });
    // QR Code OnClick Listeners

    qrimagesmall = (ImageView) v.findViewById(R.id.qrCode);

    // updateIP();

    qrimagesmall.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {

        Intent changetofullScreenqr = new Intent(getActivity(),
            FullScreenQRCode.class);
        changetofullScreenqr.putExtra("qrvalue", qrData);
        startActivity(changetofullScreenqr);
      }
    });
    // End of QR Listeners

    return v;

  }

  
  //to Update SD CARD space
  
  private void updateSDSpace() {
    String sdSpaceTextDisplay = null;

    long space = AvailableSpaceHandler.getExternalAvailableSpaceInMB();

    if (space < 50) {

      sdSpaceTextDisplay = "Warning!:(Low Space) :" + space + "MB";
    } else if (space > 1023) {
      space = AvailableSpaceHandler.getExternalAvailableSpaceInGB();
      sdSpaceTextDisplay = "Available Space: " + space + "GB";

    } else {

      sdSpaceTextDisplay = "Available Space: " + space + "MB";

    }

    sdspaceavail.setText(sdSpaceTextDisplay);
  }

  
  
  //To update IP UI
  
  void updateIP(boolean visible) {

    if (visible) {
      qrimagesmall.setVisibility(View.VISIBLE);
      if (IpAddress.getHostIPAddress().length() == 28) // Means Not
                                // Connected to
                                // any Network!
      {
        qrData = "Not Connected to any Network !";
      } else {
        qrData = "http://" + IpAddress.getHostIPAddress() + ":" + PORT;

      }

      // Getting Screen Width
      DisplayMetrics metrics = new DisplayMetrics();

      getActivity().getWindowManager().getDefaultDisplay()
          .getMetrics(metrics);
      int width = metrics.widthPixels;
      int qrCodeDimention = width / 2;

      QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(qrData, null,
          Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(),
          qrCodeDimention);

      try {
        Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
        qrimagesmall.setImageBitmap(bitmap);
      } catch (WriterException e) {
        e.printStackTrace();
      }
    } else {
      qrimagesmall.setVisibility(View.GONE);

    }

  }

}




Java Source Code List

com.bucketdevelopers.uft.CustomAdaptor.java
com.bucketdevelopers.uft.File_Download.java
com.bucketdevelopers.uft.FullScreenQRCode.java
com.bucketdevelopers.uft.Listpage.java
com.bucketdevelopers.uft.MainActivity.java
com.bucketdevelopers.uft.MyFragment.java
com.bucketdevelopers.uft.MyPageAdapter.java
com.bucketdevelopers.uft.ReceivedListHandler.java
com.bucketdevelopers.uft.ReceivedPage.java
com.bucketdevelopers.uft.Screen1.java
com.bucketdevelopers.uft.ServerService.java
com.common.methods.AlertCreator.java
com.common.methods.AvailableSpaceHandler.java
com.common.methods.ClearCache.java
com.common.methods.ExternalStorage.java
com.common.methods.IntentHelper.java
com.common.methods.IpAddress.java
com.common.methods.MimeUtils.java
com.common.methods.XMLDOMParser.java
com.common.methods.XmlParser.java
com.common.methods.qrcodelibrary.Contents.java
com.common.methods.qrcodelibrary.QRCodeEncoder.java
com.common.methods.assetsOperation.java
com.library.Httpdserver.NanoHTTPD.java