How to open dev options in Android 4.2

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
NeroVance
Posts: 201
Joined: Wed 10 Oct 2012, 23:00
Location: Halifax, Canada

#21 Post by NeroVance »

jpeps wrote:
NeroVance wrote:I did an elective at my local college on Android development, and learned exactly why I don't care for android. :wink:

Linux programming all the way 8)
...great, unless you want to program your android device.
You wanna program for a Symbian device :twisted: (no offense to Symbian users, even I am curious about the abilities it may still have)

Android as a Platform is horrific when it comes down to developing for it. It acts in ways that make me think it want's to pretend it doesn't use Java, or can use any language, but the thing is bloody java to the core, and having the GUI source in XML and strings and the like is nice if you are doing development that is cross-platform and uses multiple languages, it's just Java.

Well that's my 2 cents.

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#22 Post by jpeps »

NeroVance wrote:
Android as a Platform is horrific when it comes down to developing for it. It acts in ways that make me think it want's to pretend it doesn't use Java, or can use any language, but the thing is bloody java to the core, and having the GUI source in XML and strings and the like is nice if you are doing development that is cross-platform and uses multiple languages, it's just Java.
Understanding java is almost essential. Fortunately, there are a ton of excellent tutorials. Here's one I like using eclipse:

http://eclipsetutorial.sourceforge.net/ ... inner.html

NeroVance: I don't know about taking one android course at a community college. I've never taken a computer course, but I've done a lot of coding. I find it enjoyable, but there are lots of levels.

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#23 Post by jpeps »

Amazing...there's an android AIDE app, which is basically a complete android development environment. You can write apps right on the device itself....and it works.

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#24 Post by jpeps »

NeroVance wrote:
Android as a Platform is horrific when it comes down to developing ....
Having finished an sqlite database app with 5 layout windows that imports, exports, edits and queries anything and everything with various clickable reports (all on my cellphone), I'd have to say that the solution to every imaginable obstacle was readily available via a google search. I'm impressed at just how sophisticated and available Android is for anyone at all interested (also completely enjoyable).

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#25 Post by jpeps »

Getting simpler all the time!

http://appinventor.mit.edu/explore/

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

Dropbox SyncAPI

#26 Post by jpeps »

This is some code that exports a database file to DropBox using its SyncAPI.
You obtain an appKey & secret from DropBox, and import a jar into your lib directory. This worked to export a Library Database, so I can integrate it into all my devices.There's also some standard permission codes for the Manifest file that is well documented.

TextView and Button are user widgets; the OnClickListener is connected to the buttons, and tells the program what to do when the user clicks on it. Basically, it creates a link with Dropbox, and then performs the file writing function with the doDropBoxTest function. If the file doesn't already exist, it creates it first. Existing files didn't want to be overwritten, so needed to be deleted prior to updating. The mTestOutput.setText code is simply info that shows up on the user screen (the TextView widget).

The FindViewById code in the beginning just links a handle to widgets in the layout.xml file so you can tell them what to do.

note: The link button only shows up once to connect the app with dropbox for a particular device. The app will maintain the link even after exiting, so after that the button remains hidden (see showLinkedView) and automatically updates the file.

Code: Select all

public class MainActivity extends Activity {
    
   private static final String appKey = "MyKEY";
    private static final String appSecret = "MySECRET";
    private static final int REQUEST_LINK_TO_DBX = 0;
    private TextView mTestOutput;
    private Button mLinkButton, buttonExit;
    private DbxAccountManager mDbxAcctMgr;
   
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
	     mTestOutput = (TextView) findViewById(R.id.test_output);
	     mLinkButton = (Button) findViewById(R.id.link_button);
	     buttonExit = (Button) findViewById(R.id.buttonExit);
	     
	     buttonExit.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				
			finish();
			System.exit(0);
			}
	     });	 
	     
	     
	     mLinkButton.setOnClickListener(new OnClickListener() {
	            @Override
	            public void onClick(View v) {
	                onClickLinkToDropbox();
	            }
	     });
             mDbxAcctMgr = DbxAccountManager.getInstance(getApplicationContext(), appKey, appSecret);
  
	}

	@Override
	protected void onResume() {
		super.onResume();
		if (mDbxAcctMgr.hasLinkedAccount()) {
		    showLinkedView();
		    doDropboxTest();
		    
		} else {
			showUnlinkedView();
		}
	}
	
         private void showUnlinkedView() {
						      mLinkButton.setVisibility(View.VISIBLE); mTestOutput.setVisibility(View.GONE);
		
	}
		private void showLinkedView() {
		mLinkButton.setVisibility(View.GONE);
	        mTestOutput.setVisibility(View.VISIBLE);
		
	}
		private void onClickLinkToDropbox() {
   mDbxAcctMgr.startLink((Activity)this, REQUEST_LINK_TO_DBX);
					    }

	@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
     if (requestCode == REQUEST_LINK_TO_DBX) {
		 if (resultCode == Activity.RESULT_OK) {
		     doDropboxTest();
	     } else {
      mTestOutput.setText("Link to Dropbox failed or was cancelled.");
				            }
	   } else {
    super.onActivityResult(requestCode, resultCode, data);
				        }
				    }

 private void doDropboxTest() {
						 
 mTestOutput.setText("Dropbox Sync API Version "+DbxAccountManager.SDK_VERSION_NAME+"\n");
						 
  String packageName = "com.jpeters.myandroidlibrary2";
 
 File myFilesDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + packageName + "/files"); 

 File newFile = new File(myFilesDir, "MyLibrary.db");
						    
	try{       
    final String TEST_FILE_NAME = "MyLibrary.db";

DbxPath testPath = new DbxPath(DbxPath.ROOT, TEST_FILE_NAME);
					          
	  // Create DbxFileSystem for synchronized file access.
    DbxFileSystem dbxFs = DbxFileSystem.forAccount(mDbxAcctMgr.getLinkedAccount());
					 
 // Print the contents of the root folder.  This will block until we can
 // sync metadata the first time.
					            
List<DbxFileInfo> infos = dbxFs.listFolder(DbxPath.ROOT);
mTestOutput.append("\nContents of app folder:\n");
					       
for (DbxFileInfo info : infos) {
 mTestOutput.append("    " + info.path + ", " + info.modifiedTime + '\n');
					            
// Create a db file if it doesn't already exist.
		if (!dbxFs.exists(testPath)) {
		DbxFile  testFile = dbxFs.create(testPath);
// write existing file to dropbox	
					            	testFile.writeFromExistingFile(newFile, false);
		testFile.close();
 }	
	 else {	
	 // remove existing file to update
	dbxFs.delete(testPath);
	DbxFile  testFile = dbxFs.create(testPath);
					            	
					            	testFile.writeFromExistingFile(newFile, false);
	testFile.close();
					            }
 mTestOutput.append("\nCreated new file '" + testPath + "'.\n");	
					              
					
} catch (IOException e) {
mTestOutput.setText("Dropbox test failed: " + e);
					     }
	
    
   }
}		

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

Exporting to Dropbox from within an APP

#27 Post by jpeps »

This example exports a file by clicking on a menu item from within the app. First, connect the menu click to a function that checks whether there's a linked account. Generally, it only needs to do this once. It then connects to the export function itself.

bug fix: safer not to run the export function on the same menu click with establishing an initial connection.

Code: Select all

 private void dropboxClick() {
		  
 mDbxAcctMgr = DbxAccountManager.getInstance(getApplicationContext(), appKey, appSecret);
		  if (!mDbxAcctMgr.hasLinkedAccount()) {

mDbxAcctMgr.startLink((Activity)this, REQUEST_LINK_TO_DBX);
	
			
		  } else {
		
	 doDropboxExport();
                }
		  
}
After you have your connection, you can proceed to copy the file to your linked account. Dropbox creates a folder with the app name you registered. ("Toast" provides dialog messages like the TextEdit widget in the previous example).

Code: Select all

private void doDropboxExport() {
		 File newFile = new File(DB_FILEPATH, DATABASE_NAME);
			
		try {
 final String TEST_FILE_NAME = "MyLibrary.db";
DbxPath testPath = new DbxPath(DbxPath.ROOT, TEST_FILE_NAME);
	          
	           
DbxFileSystem dbxFs = DbxFileSystem.forAccount(mDbxAcctMgr.getLinkedAccount());
	// Create a db file if it doesn't already exist.
	        
	if (!dbxFs.exists(testPath)) {
	         DbxFile  testFile = dbxFs.create(testPath);
	      // write existing file to dropbox	
	         testFile.writeFromExistingFile(newFile, false);
	         testFile.close();
Toast.makeText(this, "Written to DropBox: " + TEST_FILE_NAME, Toast.LENGTH_SHORT).show();
	         }	
	  else {	
	         // remove existing file to update
	         dbxFs.delete(testPath);
	         DbxFile  testFile = dbxFs.create(testPath);
	         	
	         testFile.writeFromExistingFile(newFile, false);
	         testFile.close();
Toast.makeText(this, "Written to DropBox: " + TEST_FILE_NAME, Toast.LENGTH_SHORT).show();
	         }
			

		} catch (Unauthorized e) {
Toast.makeText(this, "Dropbox Failed!" + e, Toast.LENGTH_SHORT).show();
			e.printStackTrace();
} catch (DbxException e) {
			Toast.makeText(this, "Dropbox Failed!" + e, Toast.LENGTH_SHORT).show();
			e.printStackTrace();
		} catch (IOException e) {
			Toast.makeText(this, "Dropbox Failed!" + e, Toast.LENGTH_SHORT).show();
			e.printStackTrace();
		}
		
		
	}

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

Android tutorial

#28 Post by jpeps »

Helpful tutorial on moving around data between activities (via UI widgets) and storing.

Contains videos, step by step instructions, and source code that can be imported (into Eclipse).

http://www.mybringback.com/series/android-intermediate/

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

Storing and Saving Data

#29 Post by jpeps »

Example: Save and restore data internally and externally


Saving widget and variable internally with Shared Preferences:


// Save data (KEY, string)
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
Editor editor = sharedPreferences.edit();

editor.putString("total", String.valueOf(total));
editor.putString("date", dateString );
editor.putString("activity", activity );


editor.commit();





// Get Saved Data (KEY, default value)

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

// Load to EditText widget:

sumText.setText(sharedPreferences.getString("total", "0"));
// Restore variables

oldDate = sharedPreferences.getString("date", null);
activity = sharedPreferences.getString("activity", "");



Save data to external file:

// Create directory on SD storage

root = android.os.Environment.getExternalStorageDirectory();

dir = new File(root.getAbsolutePath() + "/clickData");
if(! dir.exists())

dir.mkdir();

// Create file

File file = new File(dir, "myRecord.txt");


// Print data to file

try {
FileOutputStream f = new FileOutputStream(file,true); // boolean "true" means append file
PrintWriter pw = new PrintWriter(f, true);

pw.println(dataString + " " + activity);

pw.flush();
pw.close();
f.close();

// Optional: Toast gives an onscreen info message
Toast toast = Toast.makeText(getApplicationContext(), "File written to "+file, Toast.LENGTH_SHORT);
toast.show();



} catch (FileNotFoundException e) {
Toast toast = Toast.makeText(getApplicationContext(), "File Not Found!" , Toast.LENGTH_SHORT);
toast.show();
e.printStackTrace();
} catch (IOException e) {
Toast toast = Toast.makeText(getApplicationContext(), "IO Exception Error!" , Toast.LENGTH_SHORT);
toast.show();
e.printStackTrace();
}


Read from External File:

// writes file to EditText widget (reportText)


try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;

while ((line = br.readLine()) != null) {

reportText.append(line + "\n");
}


} catch (FileNotFoundException e1) {
Toast toast = Toast.makeText(getApplicationContext(), "No Report on file", Toast.LENGTH_SHORT);
toast.show();
e1.printStackTrace();
} catch (IOException e) {
Toast toast = Toast.makeText(getApplicationContext(), "IO Exception Error!", Toast.LENGTH_SHORT);
toast.show();
e.printStackTrace();
}

afifio
Posts: 19
Joined: Sat 26 Oct 2013, 16:57

#30 Post by afifio »

Android is the future, no doubt. But its still far, I'll give it 5 or 10 years more for it to become truly mainstream. During that, we will still have "common pc" <----- common! :lol:

I did try to wet my feet with ADT, but at 400MB API and who knows whats there, it might burn my pc to crisp. Even running eclipse is trivial for me....plus...I sux at java and its damn slow.

jpeps, checkout the Actionbar Sherlock, another thing to boot up your dev is the https://f-droid.org/‎ . I do envy the android community, they make it seems like easy and I got sleepy reading even the intro to android apps, :lol:

The problem with android is - not much apps to develop, its because of its limited screen and the windowing capability (probably more apps will use the ICS windowing after this)

As I said, if you could develop for android - what will you develop ? Almost all is there already and downloadable from the market and yes, AIDE rocks! - no need 400MB download!

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#31 Post by jpeps »

afifio wrote:
I did try to wet my feet with ADT, but at 400MB API and who knows whats there, it might burn my pc to crisp. Even running eclipse is trivial for me....plus...I sux at java and its damn slow.
I wrote a few apps with AIDE on my Nexus. Version 2.16 is only 17.10 MB.
Works nicely. Java has become much faster, even on my old Dell laptops. They're actually fairly simple to write with a tool like Eclipse, and prepares you for Android.


jpeps, checkout the Actionbar Sherlock, another thing to boot up your dev is the https://f-droid.org/‎ . I do envy the android community, they make it seems like easy and I got sleepy reading even the intro to android apps, :lol:
You can access the action bar directly in later versions of android. For example, to put the date in the action bar:

Code: Select all


ActionBar ab = get ActionBar();
ab.setTitle(dateString);
I just checked out:
https://f-droid.org/repository/browse/

Nice...they include the source code for everything...what a treasure!!

As I said, if you could develop for android - what will you develop ?
:) Well, all my office software for starters. I now do case notes on my cell phone, using voice to text. I wrote psych testing apps that uses the touchscreen (on a Nexus 7) for the questionnaire (boolean..true/false)..Score, content analysis, graph, etc.. You can tailor database apps for your own purposes. I wrote an sqlite db for my library (on my phone) that interfaces with a java sqlite on my pc...also interfaces with the cloud. I just wrote an exercise app that adds points for various activities..when the date changes, it logs the results to a file and resets itself. It's always great to be able to create apps that do exactly what you want them to do, and once you start using them, new ideas keep coming.

I suppose you could also sell them. 200,000 downloads at $.99 would pay the rent.

Post Reply