Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
This should be enough to open and build the project in Eclipse, I hope.
  • Loading branch information
SamusAranX committed Sep 13, 2015
1 parent a968175 commit 5ca6e64
Show file tree
Hide file tree
Showing 10 changed files with 416 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="res"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/net.rim.ejde.BlackBerryVMInstallType/BlackBerry JRE 7.1.0"/>
<classpathentry kind="output" path="bin"/>
</classpath>
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ $RECYCLE.BIN/
Network Trash Folder
Temporary Items
.apdisk


# BlackBerry
/bin
/deliverables
29 changes: 29 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ScreenSnap</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>net.rim.ejde.internal.builder.BlackBerryPreprocessBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.rim.ejde.internal.builder.BlackBerryResourcesBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>net.rim.ejde.BlackBerryPreProcessNature</nature>
<nature>net.rim.ejde.BlackBerryProjectCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.4
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore
org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore
org.eclipse.jdt.core.compiler.source=1.3
23 changes: 23 additions & 0 deletions BlackBerry_App_Descriptor.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- This file has been generated by the BlackBerry Plugin for Eclipse v3.7.101. -->

<Properties ModelVersion="1.1.2">
<General Title="ScreenSnap" Version="1.0.0" Vendor="Peter Wunder" Description=""/>
<Application Type="BlackBerry Application" MainMIDletName="" MainArgs="" HomeScreenPosition="0" StartupTier="7" IsSystemModule="false" IsAutostartup="true"/>
<Resources hasTitleResource="false" TitleResourceBundleName="" TitleResourceBundleRelativePath="" TitleResourceBundleClassName="" TitleResourceBundleKey="" DescriptionId="">
<Icons>
<Icon CanonicalFileName="res\img\icon.png" IsFocus="false"/>
</Icons>
</Resources>
<KeywordResources KeywordResourceBundleName="" KeywordResourceBundleRelativePath="" KeywordResourceBundleClassName="" KeywordResourceBundleKey=""/>
<Compile OutputCompilerMessages="false" ConvertImages="true" CreateWarningForNoExportedRoutine="true" CompressResources="false" AliasList="">
<PreprocessorDefines/>
</Compile>
<Packaging PreBuildStep="" PostBuildStep="" CleanStep="" OutputFileName="ScreenSnap" OutputFolder="deliverables" GenerateALXFile="true">
<AlxFiles/>
</Packaging>
<HiddenProperties>
<ClassProtection/>
<PackageProtection/>
</HiddenProperties>
<AlternateEntryPoints/>
</Properties>
Binary file added res/img/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions src/screensnap/ConfigScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package screensnap;

import net.rim.device.api.system.ApplicationDescriptor;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.CheckboxField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.component.StandardTitleBar;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.Font;

/**
* A class extending the MainScreen class, which provides default standard
* behavior for BlackBerry GUI applications.
*/
public final class ConfigScreen extends MainScreen implements FieldChangeListener
{
public ConfigScreen() {
// Get the app name
String appName = ApplicationDescriptor.currentApplicationDescriptor().getModuleName();

// Set up a standard title bar
StandardTitleBar sTitleBar = new StandardTitleBar().addTitle(appName).addClock().addNotifications().addSignalIndicator();
sTitleBar.setPropertyValue(StandardTitleBar.PROPERTY_BATTERY_VISIBILITY, StandardTitleBar.BATTERY_VISIBLE_LOW_OR_CHARGING);
setTitleBar(sTitleBar);

// Get the system font and set up a little footer label
Font systemFont = Font.getDefault().derive(Font.PLAIN, 6, Ui.UNITS_pt);
RichTextField header = new RichTextField("ScreenSnap, a thingy by @SamusAranX", RichTextField.TEXT_JUSTIFY_HCENTER|Field.NON_FOCUSABLE);
header.setPadding(6, 0, 6, 0);
header.setFont(systemFont, true);
this.setStatus(header); // setStatus() refers to the status area of a MainScreen, which essentially is a field that's docked at the bottom

VerticalFieldManager vfm = new VerticalFieldManager();

String mediaCardName = System.getProperty("fileconn.dir.memorycard.name"); // Get the media card's name, if there is one
// I'm not actually sure what happens if there is no memory card, as I'm too lazy to take my phone apart to remove it

Object storeOnCardObj = ((ScreenSnapApp)UiApplication.getUiApplication()).persistentStore.get("storeOnCard");
boolean storeOnCard = false;
if(storeOnCardObj != null) // Inline ternary operators would not work here, for some reason
storeOnCard = ((Integer)storeOnCardObj).intValue() == 1;

boolean mediaCardPresent = ((ScreenSnapApp)UiApplication.getUiApplication()).mediaCardPresent; // Is there a media card inserted?

CheckboxField cbf = new CheckboxField("Store screenshots on " + mediaCardName, storeOnCard); // Initialize a check box with the previously loaded value
cbf.setChangeListener(this); // the listener method is at the bottom of the file
cbf.setEnabled(mediaCardPresent); // there's not much point to this if there is no media card inserted

// Add everything to the screen
vfm.add(cbf);
this.add(vfm);

// gotta do this after everything's been added to this screen because otherwise it'll segfault
cbf.setFocus();
}

public void onDisplay() {
System.out.println("ScreenSnap: onDisplay");
}

public boolean onClose() {
UiApplication.getUiApplication().requestBackground(); // Don't actually close the app, just move it to the background
return true;
}

public void fieldChanged(Field field, int context) {
System.out.println("ScreenSnap: field is null? " + field == null);
CheckboxField cbf = (CheckboxField)field;

// Save the new value
((ScreenSnapApp)UiApplication.getUiApplication()).persistentStore.put("storeOnCard", new Integer(cbf.getChecked() ? 1 : 0));
((ScreenSnapApp)UiApplication.getUiApplication()).persistentStore.commit();
}
}
48 changes: 48 additions & 0 deletions src/screensnap/ConvenienceKeyListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package screensnap;

import java.io.IOException;

import net.rim.device.api.system.KeyListener;
import net.rim.device.api.ui.Keypad;
import net.rim.device.api.ui.UiApplication;

public final class ConvenienceKeyListener implements KeyListener {

public boolean keyChar(char key, int status, int time) {
return false;
}

public boolean keyDown(int keycode, int time) {
if (Keypad.KEY_CONVENIENCE_1 == Keypad.key(keycode)) {
System.out.println("ScreenSnap: Convenience key pressed");

try {
if (((ScreenSnapApp)UiApplication.getUiApplication()).takeScreenshot()) {
System.out.println("ScreenSnap: Screenshot taken.");
} else {
System.out.println("ScreenSnap: Couldn't take screenshot.");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("ScreenSnap: Error, couldn't take screenshot.");
}

return true;
}

return false;
}

public boolean keyRepeat(int keycode, int time) {
return false;
}

public boolean keyStatus(int keycode, int time) {
return false;
}

public boolean keyUp(int keycode, int time) {
return false;
}
}
95 changes: 95 additions & 0 deletions src/screensnap/PersistentStoreHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package screensnap;

import java.util.Hashtable;

import net.rim.device.api.crypto.SHA1Digest;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
import net.rim.device.api.util.Persistable;

/**
* Use this class like so:
* <code>
* PersistentStoreHelper store = PersistentStoreHelper.getInstance();
* Vector msgs = (Vector)store.get("chatMsgs");
* if (msgs == null) {
* msgs = new Vector();
* store.put("chatMsgs", msgs);
* }
* msgs.addElement("this is a new chat message");
* store.put("someOtherKey", someOtherValue);
* // commit will save changes both to the msgs list, and to `someOtherValue` added
* store.commit();
* </code>
*/
public class PersistentStoreHelper implements Persistable { // only Persistable so inner class can be!

/**
* persistentHashtable is now an instance of a class that
* only exists in your app
*/
private MyAppsHashtable persistentHashtable;
private PersistentObject persistentObject;

/** PersistentStoreHelper is a singleton */
private static PersistentStoreHelper instance = null;

/** call this to get access to the methods of this class */
public static PersistentStoreHelper getInstance() {
if (instance == null) {
instance = new PersistentStoreHelper();
}
return instance;
}

private long getLongKey(String key) {
SHA1Digest sha1Digest = new SHA1Digest();
sha1Digest.update(key.getBytes());
byte[] hashValBytes = sha1Digest.getDigest();
long hashValLong = 0;

for(int i = 0; i < 8; ++i) {
hashValLong |= ((long)(hashValBytes[i]) & 0x0FF) << (8*i);
}

return hashValLong;
}

/** This constructor is private to en */
private PersistentStoreHelper() {
final long KEY = getLongKey("com.peterwunder.ScreenSnap");
persistentObject = PersistentStore.getPersistentObject(KEY);
if (persistentObject.getContents() == null) {
persistentHashtable = new MyAppsHashtable();
persistentObject.setContents(persistentHashtable);
} else {
persistentHashtable = (MyAppsHashtable)persistentObject.getContents();
}
}

/** use this method to retrieve a saved value from the store, by its key */
public Object get(String key) {
return persistentHashtable.get(key);
}

/** use this method to add a value to be saved in the store */
public void put(String key, Object value) {
persistentHashtable.put(key, value);
}

/** call this when you want to make sure all recent changes are saved to device storage */
public void commit() {
persistentObject.setContents(persistentHashtable);
persistentObject.commit();
}

public void clear() {
persistentHashtable.clear();
persistentObject.setContents(persistentHashtable);
persistentObject.commit();
}

private class MyAppsHashtable extends Hashtable implements Persistable {
// don't need anything else ... the declaration does it all!
}
}
Loading

0 comments on commit 5ca6e64

Please sign in to comment.