Re: [android-developers] Re: Compression of files kept in Assets folder and in res\raw folder.

2014-03-23 Thread sushant sharma
This sounds something I need. I will try the same and update the thread.
Thanks Leonid.


On Mon, Mar 24, 2014 at 11:33 AM, Leo  wrote:

> Sure, you can access your entire apk from within NDK and native code, but
> it'll be a little bit harder than from java.
>
> 1. You need to include libzip into your project and compile it together
> with your own C++ code.
> 2. Pass the full path to your apk file from Java to C++ method
> 3. Open APK with libzip call and the given path.
> 4. Read contents using libzip.
>
> See this link to explanation and examples of code:
>
>
> http://www.anddev.org/ndk_opengl_-_loading_resources_and_assets_from_native_code-t11978.html
>
>
>
> On Monday, March 24, 2014 8:45:40 AM UTC+4, sushant sharma wrote:
>
>> Thanks for the reply Leonid. This is close to what I am looking for.
>> What is problem is that I want to access the file from the native code.
>>
>> From the java code, I would have used the asset manager itself.
>>
>> These are my requirements:
>> 1) I want to access the file through the native code.
>> 2) preferably I want a file handle. And not buffer(like assetmanger gives)
>>
>> Is there's a similar utility provided by the ndk?
>>
>> Thanks
>> Sushant
>> On Mar 21, 2014 3:07 PM, "Leo"  wrote:
>>
>>> Short snippet of code - how to read a file from your APK with Zip:
>>>
>>> {
>>> String path = getApplication().getPackageCodePath();
>>>  ZipFile zfile = new ZipFile(path);
>>> String fileName = new String("filepath/inside_apk/file.txt");
>>> ZipEntry zentry = zfile.getEntry(fileName);
>>>  long siz = zentry.getSize();
>>>  byte[] buf=new byte[(int) siz];
>>>  InputStream istream = zfile.getInputStream(zentry);
>>>  int ret = istream.read(buf);
>>>  istream.close();
>>> }
>>>
>>> This is just a snippet and need proper handling of exceptions and file
>>> length (if it is too large)...
>>>
>>> On Friday, March 21, 2014 1:24:56 PM UTC+4, Leo wrote:

 Hi,

 According to 'unzip -v' command for my own apk file, the zip-file is
 compressed:

4653  Defl:N 1132  76%  03-19-14 00:18  e65916c3
  assets/layout/gfx720/profile.xml

 76% of the file is the compression ratio.

 Use built-in java Zip* classes to access your contents inside APK if
 you don't want to use AssetManager:

 http://developer.android.com/reference/java/util/zip/ZipFile.html
 http://developer.android.com/reference/java/util/zip/ZipInpu
 tStream.html

 On Thursday, March 20, 2014 8:27:14 PM UTC+4, sushant sharma wrote:
>
> Hi,
> The questions I have is:
>
> 1) Are the files kept in "assets" folder compressed when apk is
> zipped.
> 2) Are the files kept in "res/raw" folder compressed when apk is
> zipped.
>
>
> Lets say if the answer to the questions is Yes, ie, the files are
> compressed.
> 1) Does this mean that AssetManager does the decompression and then
> gives us the istream?
> 2) Lets assume that I don't go through the AssetManager and read the
> file directly by accessing the apk path and the offset (The FileDescriptor
> method). If the file was compressed, the bytes I will read after doing an
> fopen() will not make sense to me, right?
>
>
> Thanks
> Sushant
>
  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Android Developers" group.
>>> To post to this group, send email to android-d...@googlegroups.com
>>>
>>> To unsubscribe from this group, send email to
>>> android-developers+unsubscr...@googlegroups.com
>>> For more options, visit this group at
>>> http://groups.google.com/group/android-developers?hl=en
>>> ---
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Android Developers" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/
>>> topic/android-developers/zXDE7Rli4Ps/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> android-developers+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "Android Developers" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/android-developers/zXDE7Rli4Ps/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> android-developers+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sushant Sharma
*Kala Ka Aadar Ho*
*Manch k

Re: [android-developers] Re: Compression of files kept in Assets folder and in res\raw folder.

2014-03-23 Thread Leo
Sure, you can access your entire apk from within NDK and native code, but 
it'll be a little bit harder than from java.

1. You need to include libzip into your project and compile it together 
with your own C++ code.
2. Pass the full path to your apk file from Java to C++ method
3. Open APK with libzip call and the given path.
4. Read contents using libzip.

See this link to explanation and examples of code:

http://www.anddev.org/ndk_opengl_-_loading_resources_and_assets_from_native_code-t11978.html



On Monday, March 24, 2014 8:45:40 AM UTC+4, sushant sharma wrote:
>
> Thanks for the reply Leonid. This is close to what I am looking for. 
> What is problem is that I want to access the file from the native code.
>
> From the java code, I would have used the asset manager itself.
>
> These are my requirements:
> 1) I want to access the file through the native code.
> 2) preferably I want a file handle. And not buffer(like assetmanger gives)
>
> Is there's a similar utility provided by the ndk?
>
> Thanks
> Sushant
> On Mar 21, 2014 3:07 PM, "Leo" > wrote:
>
>> Short snippet of code - how to read a file from your APK with Zip:
>>
>> {
>> String path = getApplication().getPackageCodePath();
>>  ZipFile zfile = new ZipFile(path);
>> String fileName = new String("filepath/inside_apk/file.txt");
>> ZipEntry zentry = zfile.getEntry(fileName);
>>  long siz = zentry.getSize();
>>  byte[] buf=new byte[(int) siz];
>>  InputStream istream = zfile.getInputStream(zentry);
>>  int ret = istream.read(buf);
>>  istream.close(); 
>> }
>>
>> This is just a snippet and need proper handling of exceptions and file 
>> length (if it is too large)...
>>
>> On Friday, March 21, 2014 1:24:56 PM UTC+4, Leo wrote:
>>>
>>> Hi,
>>>
>>> According to 'unzip -v' command for my own apk file, the zip-file is 
>>> compressed:
>>>
>>>4653  Defl:N 1132  76%  03-19-14 00:18  e65916c3 
>>>  assets/layout/gfx720/profile.xml
>>>
>>> 76% of the file is the compression ratio.
>>>
>>> Use built-in java Zip* classes to access your contents inside APK if you 
>>> don't want to use AssetManager:
>>>
>>> http://developer.android.com/reference/java/util/zip/ZipFile.html
>>> http://developer.android.com/reference/java/util/zip/ZipInputStream.html
>>>
>>> On Thursday, March 20, 2014 8:27:14 PM UTC+4, sushant sharma wrote:

 Hi, 
 The questions I have is: 

 1) Are the files kept in "assets" folder compressed when apk is zipped. 
 2) Are the files kept in "res/raw" folder compressed when apk is 
 zipped. 


 Lets say if the answer to the questions is Yes, ie, the files are 
 compressed. 
 1) Does this mean that AssetManager does the decompression and then 
 gives us the istream?
 2) Lets assume that I don't go through the AssetManager and read the 
 file directly by accessing the apk path and the offset (The FileDescriptor 
 method). If the file was compressed, the bytes I will read after doing an 
 fopen() will not make sense to me, right?


 Thanks 
 Sushant

>>>  -- 
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to 
>> android-d...@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>> --- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Android Developers" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/android-developers/zXDE7Rli4Ps/unsubscribe
>> .
>> To unsubscribe from this group and all its topics, send an email to 
>> android-developers+unsubscr...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[android-developers] How to find outgoing call is answered

2014-03-23 Thread Arun Kumar K
Hi,


I am developing a small application. *i don't know how to find My outgoing
call is answered or not. *If any one knows please tell me..


-- 
*Regards*
*Arun*

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [android-developers] Re: Compression of files kept in Assets folder and in res\raw folder.

2014-03-23 Thread sushant sharma
Thanks for the reply Leonid. This is close to what I am looking for.
What is problem is that I want to access the file from the native code.

>From the java code, I would have used the asset manager itself.

These are my requirements:
1) I want to access the file through the native code.
2) preferably I want a file handle. And not buffer(like assetmanger gives)

Is there's a similar utility provided by the ndk?

Thanks
Sushant
On Mar 21, 2014 3:07 PM, "Leo"  wrote:

> Short snippet of code - how to read a file from your APK with Zip:
>
> {
> String path = getApplication().getPackageCodePath();
> ZipFile zfile = new ZipFile(path);
> String fileName = new String("filepath/inside_apk/file.txt");
> ZipEntry zentry = zfile.getEntry(fileName);
> long siz = zentry.getSize();
>  byte[] buf=new byte[(int) siz];
> InputStream istream = zfile.getInputStream(zentry);
>  int ret = istream.read(buf);
> istream.close();
> }
>
> This is just a snippet and need proper handling of exceptions and file
> length (if it is too large)...
>
> On Friday, March 21, 2014 1:24:56 PM UTC+4, Leo wrote:
>>
>> Hi,
>>
>> According to 'unzip -v' command for my own apk file, the zip-file is
>> compressed:
>>
>>4653  Defl:N 1132  76%  03-19-14 00:18  e65916c3
>>  assets/layout/gfx720/profile.xml
>>
>> 76% of the file is the compression ratio.
>>
>> Use built-in java Zip* classes to access your contents inside APK if you
>> don't want to use AssetManager:
>>
>> http://developer.android.com/reference/java/util/zip/ZipFile.html
>> http://developer.android.com/reference/java/util/zip/ZipInputStream.html
>>
>> On Thursday, March 20, 2014 8:27:14 PM UTC+4, sushant sharma wrote:
>>>
>>> Hi,
>>> The questions I have is:
>>>
>>> 1) Are the files kept in "assets" folder compressed when apk is zipped.
>>> 2) Are the files kept in "res/raw" folder compressed when apk is zipped.
>>>
>>>
>>> Lets say if the answer to the questions is Yes, ie, the files are
>>> compressed.
>>> 1) Does this mean that AssetManager does the decompression and then
>>> gives us the istream?
>>> 2) Lets assume that I don't go through the AssetManager and read the
>>> file directly by accessing the apk path and the offset (The FileDescriptor
>>> method). If the file was compressed, the bytes I will read after doing an
>>> fopen() will not make sense to me, right?
>>>
>>>
>>> Thanks
>>> Sushant
>>>
>>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "Android Developers" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/android-developers/zXDE7Rli4Ps/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> android-developers+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[android-developers] How to inject mock objects in Android?

2014-03-23 Thread Yuvi

 Hi,

I am facing issue while unit testing :

// Service class that have to be tested.

class FooService extends Service{

public static FooService sFooService;

private Bar mBar = new Bar();
//Other private objects

@Override
protected void onCreate()
{
sFooService = this;
}

public static FooService getInstance()
{
return sFooService;
}

@Override
protected void onDestroy()
{
sFooService = null;
}

public void doSomething()
{
//do Some stuff here
if(done)
{
mBar.perfomAction(true);
// Now this performAction method doing many stuffs using some other 
classes
// that may have dependency and initialized from some else. Hence 
throwing exceptions.
// Therefore need to mock Bar class. but how ??
}
else
{
mBar.perfomAction(false);
}
}}


// Test Class

class FooTest extends ServiceTestCase{

protected void setUp() throws Exception
{
super.setUp();
MockitoAnnotations.initMocks(this);
startService(new Intent(getContext(), FooService.class));

}

protected void tearDown() throws Exception
{
super.tearDown();
}

public void testdoSomething()
{
Bar bar = mock(bar.class);
doThrow(new RuntimeException re).when(bar).performAction(true);

//How to inject bar mocked object?

assertNotNull(FooService.getInstance());

try
{
FooService.getInstance().doSomeThing();
Assert.Fail("Runtime exception should be thrown");
}
catch (RuntimeException re)
{

}
}}


Now, here how can I inject bar mocked object which is created using Mockito 
?

I have googled this, and found that some guys suggested to create getter 
and setter for Bar class. Which I don't think is a valid solution, because 
there could be number of private object, that will be visible to outside 
FooService class.

Regards,

Yuvi

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.