» »

[android] vstavljanje slike

[android] vstavljanje slike

messi ::

Hočem vstaviti sliko vendar mi zadeve ne deluje in sicer me zanima ali moram kaj dodati v xml, če hočem da mi dela, vendar jaz nalagam ta imige v drawview,..ali pa je nekaj narobe v tej kodi..

package com.example.pii;
 
 
public class Draw extends Activity  {
	private static final String TAG = "FingerPaint";
  
    //a variable to store the system brightness  
    private int brightness;  
    //the content resolver used as a handle to the system's settings  
    private ContentResolver cResolver;  
    //a window object, that will store a reference to the current window  
    private Window window;  
    /** Menu ID for the command to clear the window. */
    private static final int CLEAR_ID = Menu.FIRST;
    /** Menu ID for the command to toggle fading. */
    private static final int SAMPLES_ID = Menu.FIRST+1;
    /** Menu ID for about **/
    private static final int ABOUT_ID = Menu.FIRST+2;
    private static final int INSERT_ID = Menu.FIRST+3;
 
    /** The view responsible for drawing the window. */
    TesterView mView;
  
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Set full screen view
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);  
      
      
        setRequestedOrientation(getResources().getConfiguration().orientation);
         
        // Create and attach the view that is responsible for painting.
        mView = new TesterView(this, null, 0);
     
        setContentView(	R.layout.activity_main);
        mView =(TesterView) findViewById (R.id.DrawView);
      //  mView=(mView) findViewById (R.id.DrawView);
      // mView = new findViewById(mView);
        mView.requestFocus();
       
   
 }
 
 
 
 
@Override public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, CLEAR_ID, 0, "Clear");
    menu.add(0, SAMPLES_ID, 0, "Samples").setCheckable(true);
    menu.add(0, ABOUT_ID, 0, "Version "+this.getString(R.string.app_name));
    menu.add(0, INSERT_ID, 0, "Insert");
    return super.onCreateOptionsMenu(menu);
}
 
@Override public boolean onPrepareOptionsMenu(Menu menu) {
 //   menu.findItem(SAMPLES_ID).setChecked(mSamples);
    return super.onPrepareOptionsMenu(menu);
}
 
@Override public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case CLEAR_ID:
            mView.clear();
            return true;
        case SAMPLES_ID:
            mView.bShowSamples = !mView.bShowSamples;
            return true;
        case ABOUT_ID:
            return true;
        case INSERT_ID:
        	setCustomBackground(mView);
        	return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 

void setCustomBackground(TesterView v) {
	Intent fileChooserIntent = new Intent();
	fileChooserIntent.addCategory(Intent.CATEGORY_OPENABLE);
	fileChooserIntent.setType("image/*");
	fileChooserIntent.setAction(Intent.ACTION_GET_CONTENT);
	startActivityForResult(Intent.createChooser(fileChooserIntent, "Select Picture"), 1);

	/*
	// menu option for setting a custom background
	String Url = "http://www.google.ca";	// http://www.google.ca
	Intent fileChooserIntent = new Intent(Intent.ACTION_CHOOSER, Uri.parse(Url));
	this.startActivity(fileChooserIntent);
	*/
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	// if statement prevents force close error when picture isn't selected
	if (resultCode == RESULT_OK)
	{
    	Uri resultUri = data.getData();
    	//String resultString = data.getData().toString();
    	
    	String drawString = resultUri.getPath();
    	String galleryString = getGalleryPath(resultUri);
    	
    	// if Gallery app was used
    	if (galleryString != null)
    	{
    		Log.d(TAG, galleryString);
    		drawString = galleryString;
    	}
    	// else another file manager was used
    	else
    	{
    		Log.d(TAG, drawString);
	    	//File Manager: "content://org.openintents.cmfilemanager/mimetype//mnt/sdcard/DCIM/Camera/IMG_20110909_210412.jpg"
	    	//ASTRO:        "file:///mnt/sdcard/DCIM/Camera/IMG_20110924_133324.jpg"
	    	if (drawString.contains("//"))
	    	{
	    		drawString = drawString.substring(drawString.lastIndexOf("//"));
	    	}
    	}
    	
    	// set the background to the selected picture
    	if (drawString.length() > 0)
    	{
    		Drawable drawBackground = Drawable.createFromPath(drawString);
    		mView.setBackgroundDrawable(drawBackground);
    	}
    	
	}
}

// used when trying to get an image path from the URI returned by the Gallery app
public String getGalleryPath(Uri uri) {
	String[] projection = { MediaStore.Images.Media.DATA };
	Cursor cursor = managedQuery(uri, projection, null, null, null);
	
	if (cursor != null)
	{
		int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
		cursor.moveToFirst();
		return cursor.getString(column_index);
	}
	
	
	return null;
}


@Override protected void onResume() {
    super.onResume();
    // If fading mode is enabled, then as long as we are resumed we want
    // to run pulse to fade the contents.
}
 
@Override protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    // Save away the fading state to restore if needed later.  Note that
    // we do not currently save the contents of the display.
}
 
@Override protected void onPause() {
    super.onPause();
    // Make sure to never run the fading pulse while we are paused or
    // stopped.
  }
 
 
private Handler mHandler = new Handler() {
    @Override public void handleMessage(Message msg) {
        switch (msg.what) {
            // Upon receiving the fade pulse, we have the view perform a
            // fade and then enqueue a new message to pulse at the desired
            // next time.
            default:
                super.handleMessage(msg);
        }
    }
};
 
 
}



package nt.finger.paint;

import java.io.File;
import java.io.FilenameFilter;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

public class FileChooser extends Activity {
	private static final String TAG = "FileChooser";
	private String[] mFileList;
	private File mPath = new File(Environment.getExternalStorageDirectory() + "//yourdir//");
	private String mChosenFile;
	private static final String JPG = ".jpg";
	private static final String JPEG = ".jpeg";
	private static final String PNG = ".png";
	private static final int DIALOG_LOAD_FILE = 1000;

	@Override
    public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        // Set full screen view
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        
        loadFileList();
	}
	
	private void loadFileList() {
		try {
			mPath.mkdirs();
		}
		catch(SecurityException e) {
			Log.e(TAG, "unable to write on the SD card " + e.toString());
		}
		
		if (mPath.exists()) {
			FilenameFilter filter = new FilenameFilter() {
				public boolean accept(File dir, String filename) {
					File sel = new File(dir, filename);
					return filename.contains(JPG) || filename.contains(JPEG) || filename.contains(PNG) || sel.isDirectory();
				}
			};
			mFileList = mPath.list(filter);
		} else {
			mFileList = new String[0];
		}
	}
	
	protected Dialog onCreateDialog(int id) {
		Dialog dialog = null;
		AlertDialog.Builder builder = new Builder(this);
		
		switch (id) {
		case DIALOG_LOAD_FILE :
			builder.setTitle("Choose your background");
			if (mFileList == null) {
				Log.e(TAG, "Showing file chooser before loading the file list");
				dialog = builder.create();
				return dialog;
			}
			builder.setItems(mFileList, new DialogInterface.OnClickListener(){
				public void onClick(DialogInterface dialog, int which){
					mChosenFile = mFileList[which];
					// do other shit with file
				}
			});
			break;
		}
		dialog = builder.show();
		return dialog;
	}
}

dolenc ::

Sem odpru obe temi in v napačni odgovoril, se nanaša na vprašanje v tisti temi kako porinit slikco v emulator...

Lahko preko ADBja, Push

Zgodovina sprememb…

  • spremenil: dolenc ()

messi ::

Ma kdo idejo zakaj se mi sesuva zadeva...


09-05 18:39:19.958: W/dalvikvm(870): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
09-05 18:39:20.068: E/AndroidRuntime(870): FATAL EXCEPTION: main
09-05 18:39:20.068: E/AndroidRuntime(870): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.pi1_2/com.example.pi1_2.MainActivity}: java.lang.ClassNotFoundException: com.example.pi1_2.MainActivity
09-05 18:39:20.068: E/AndroidRuntime(870): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
09-05 18:39:20.068: E/AndroidRuntime(870): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-05 18:39:20.068: E/AndroidRuntime(870): at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-05 18:39:20.068: E/AndroidRuntime(870): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-05 18:39:20.068: E/AndroidRuntime(870): at android.os.Handler.dispatchMessage(Handler.java:99)
09-05 18:39:20.068: E/AndroidRuntime(870): at android.os.Looper.loop(Looper.java:137)
09-05 18:39:20.068: E/AndroidRuntime(870): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-05 18:39:20.068: E/AndroidRuntime(870): at java.lang.reflect.Method.invokeNative(Native Method)
09-05 18:39:20.068: E/AndroidRuntime(870): at java.lang.reflect.Method.invoke(Method.java:511)
09-05 18:39:20.068: E/AndroidRuntime(870): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-05 18:39:20.068: E/AndroidRuntime(870): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-05 18:39:20.068: E/AndroidRuntime(870): at dalvik.system.NativeStart.main(Native Method)
09-05 18:39:20.068: E/AndroidRuntime(870): Caused by: java.lang.ClassNotFoundException: com.example.pi1_2.MainActivity
09-05 18:39:20.068: E/AndroidRuntime(870): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
09-05 18:39:20.068: E/AndroidRuntime(870): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
09-05 18:39:20.068: E/AndroidRuntime(870): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
09-05 18:39:20.068: E/AndroidRuntime(870): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
09-05 18:39:20.068: E/AndroidRuntime(870): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
09-05 18:39:20.068: E/AndroidRuntime(870): ... 11 more

messi ::

ali prilimam kodo samo je izjemno dolga 600 vrstic, mogoče je bolje če mi nekdo razloži, ali pa pove kako naj te napake berem..

messi ::

Smo popravl prejšne crashe ima kdo kako idejo kaka napaka je v vzgornjem isertingu slike. Če ma kdo kako idejo mi naj prosim prosim pomaga..

Mavrik ::

Premalo stacktracea si prilepil. Lepo se pomikaj navzdol in gledaj kaki exceptioni so se ti vrgli po vrsti.
The truth is rarely pure and never simple.

messi ::

Nobeni le insertat sliko mi ne more, po tisti kodi..Testiram pa na realnem sistemu ker na drugi ne morem..

messi ::

Zanima me kako se reče zadevi da bi naredil nekako takole:
Gumbe v orodni vrstici pa nebi bili gumbi vendar slikice primer je pain ..
https://play.google.com/store/apps/deta...
Takole kot prikazujejo spodnji gumbi, kako bi dodal tole, ne zanima me koda ampak kako se temu reče. Hvala lepa..


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

[android] java.lang.RuntimeException

Oddelek: Programiranje
141075 (767) piki12
»

Programiranje problem android

Oddelek: Programiranje
51170 (935) g333kk
»

[Android] Aplikacija se zruši

Oddelek: Programiranje
6813 (650) g333kk
»

android črta

Oddelek: Programiranje
412395 (1666) g333kk
»

[android] crash

Oddelek: Programiranje
61336 (1145) messi

Več podobnih tem